• Post Reply Bookmark Topic Watch Topic
  • New Topic

final classes vs immutable classes??  RSS feed

 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers!

I have a bit doubt in the case of final and immutable classes in java, please explain the concepts with example .
is it both having same meaning ??
awaiting for genuine reply......

Thanks..
Vivek
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here you go !
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16007
87
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a class is final, it just means that you cannot subclass it. Immutable means that you cannot change the state of an object after it has been created. Making classes immutable has many advantages, see this article for more details.

When you want to make a class immutable, you should make it final. But just making it final does not by itself make the class immutable.
 
viki Bhardwaj
Ranch Hand
Posts: 74
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:When a class is final, it just means that you cannot subclass it. Immutable means that you cannot change the state of an object after it has been created. see this article for more details.



yes! this is pretty enough to clear my doubt...
Thanks ... Jesper!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!