Can anybody answer me?
What is an Immutable Class, and how to make a Class explicitly "Immutable"?
-
Immutable Class (4 messages)
- Posted by: srikanth yadav
- Posted on: June 28 2005 06:30 EDT
Threaded Messages (4)
- public final class by Biswa Das on June 28 2005 10:28 EDT
- public final class by soudathikar madhu raj on July 02 2005 03:52 EDT
- let's see by vijay kumar on June 28 2005 16:03 EDT
- Immutable Class by Javin Paul on October 24 2010 11:47 EDT
-
public final class[ Go to top ]
- Posted by: Biswa Das
- Posted on: June 28 2005 10:28 EDT
- in response to srikanth yadav
The term immutable is not appropriate.
But unfortunately this is how it is termed :-( -
public final class[ Go to top ]
- Posted by: soudathikar madhu raj
- Posted on: July 02 2005 03:52 EDT
- in response to Biswa Das
The term immutable is used to be mean that once an object is created, its content cannot be changed
As some one has replied "String" class is a best example of an immutable class
To create a object which is immutable u need to make sure that the following conditions are met
1)The Class should be final
2)The Properties of the class should be private and should not have any setter methods
The above mentioned are bare minimum conditions that needs to be satisfied to make the object immutable -
let's see[ Go to top ]
- Posted by: vijay kumar
- Posted on: June 28 2005 16:03 EDT
- in response to srikanth yadav
The ideal name should have been 'RememberWhenYouModifyMeYouArePayingByCreatingNewObjects' ;)
String class is the most common example isn't it?
If u ever used the method <somestringobject>.replace u know what that-can't-pronounce-name is doing :) -
Immutable Class[ Go to top ]
- Posted by: Javin Paul
- Posted on: October 24 2010 11:47 EDT
- in response to srikanth yadav
immutable class is something whose state can not be changed e.g. String