3 ms·
While I mostly agree, getters without setters is a nice way to expose that youre data is immutable rather than relying on final fields
by iamandoni 9y ago
While I mostly agree, getters without setters is a nice way to expose that youre data is immutable rather than relying on final fields
- opmac 9y agoJust use public final. That is the defacto way to make immutable data classes. Why would a data class need non final fields?
- arthur_pryor 9y agoi'm a little rusty on my java, but i don't think this will work for non-constants (i.e. it won't work for things you don't set at compile time). to my knowledge, there's no "make this a constant after the first time the value is set" declaration in java (or any language that i'm aware of).
- dhosek 9y agoIf you declare a field final in Java, you either need to set it at declaration or in the constructor, so it will work with things set at compile time.