Ankit Garg wrote:
Minhaj kaimkhani wrote:Immutable objects are objects that do not change state?? are you agree on this??
You are right Minhaj, but what you said in your previous post is not correct
Minhaj kaimkhani wrote:make the class final make fields private and final
or
Implement Singleton Pattern.
To be immutable, a class doesn't need to implement singleton pattern (in fact that actually doesn't has anything to do with immutable classes) and marking fields final isn't necessary either...
Yes Ankit. Singleton Pattern is like one Instance per class. In Singleton you create a Private Constructor, Declare a Static variable of same Class type and provide a Static get method which will create/or point to existing instance of the class. One can access instance of class by Static call to getter method.
But please can some one explain for Immutable if we declare class Final and fields Private and Final makes a class immutable???
Final means no subclass possible means no one can extend that class.