Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final & Immutable class

 
Rahul Kumar Tiwari
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Some body told me that immutable class (Like String) that mean this class is define with final keyword but i am looking that StringBuffer Class is also a final class and it is mutable class. can any body clear me difference between final and immutable class.

Thanks
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making a class final doesn't mean that the class itself is final. If a class is immutable, you can't change the state of that class.

In String versus StringBuffer case,


Hope it helps.

 
Rahul Kumar Tiwari
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

But please tell me if all final class is not a immutable class then what properties of a final class make it immutable,
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do not provide access to the class's instance variables (no setters), it will be immutable.
 
Rahul Kumar Tiwari
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks You Very Much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic