immutable means : my public visible state cannot change after initialization
Mark the class as final
mark them all the members are final
set them explictly in static block or via constructor.
method all members as private
no methods to modify the state
be extremely careful to limit access to mutable components - use defensive copy
one of the great advantages are that immutable objects are thread safe
Why - values will never changes, they are free to read at any time by any one and require no synchoranization.
No comments:
Post a Comment