public final instead of getters to offer access to immutable variables
Context and Problem Statement
When making immutable data accessible in a java class, should it be using getters or by non-modifiable fields?
- Offer public static field
- Offer getters
Chosen option: “Offer public static field”, because getters used to be a convention which was even more manifested due to libraries depending on the existence on getters/setters. In the case of immutable variables, adding public getters is just useless since one is not hiding anything.
- Shorter code
- newcomers could get confused, because getters/setters are still taught