NOTE
Immutable Object
How to create an immutable object.
This is a historical learning note and may contain outdated or incomplete understanding.
How to Create an Immutable Object
- Apply
finalto the class. - Apply
finalto internal fields.- If the field is a reference to an object:
- Do not expose a method that modifies the internal field value.
- If it is returned externally, return a copied object.
- If the field is a reference to an object:
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub