Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final classes vs immutable classes??

 
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
Saloon Keeper
Posts: 15274
37
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic