I have a query regarding creating a Immutable class. Following are the points which I take in consideration:
- Make the class final
- Make all members final, set them explicitly, in a static block, or in the constructor
- Make all members private
- No Methods that modify state
- Be extremely careful to limit access to mutable member components(remember the field may be final but the object can still be mutable. ie private final Date imStillMutable) - See defensive copying or its cousin copy constructors for more info.
But I did not understand the 5 point completely at all, could you please advise or show me a example in which the 5 point is clear in that example?