Sunday 22 February 2015

How to create a immutable object in Java? Does all property of immutable object needs to be final?

To create a object immutable You need to make the class final and all its member final so that once objects gets crated no one can modify its state.
You can achieve same functionality by making member as non final but private and not modifying them except in constructor.

No comments:

Post a Comment