4 ms·
> If a class can't work within these constraints, then it can declare the variable as Option<T> initialized to None, and then it is back to the normal Java sema
by TheLoneWolfling 11y ago
> If a class can't work within these constraints, then it can declare the variable as Option<T> initialized to None, and then it is back to the normal Java semantics for that one variable.
By doing that you lose the safety of variables being marked final.
I wish there was a way to seal a variable such that it could not be changed (in the same sense that final works in, not truly readonly) after a certain point, but it could be before then.
I find myself writing far too many variables that should be final, and indeed are final after a certain point, but cannot be marked as such because said point is after the constructor. In particular with lazy-loading.
- TheCoelacanth 11y agoA final variable must be assigned in the constructor, so it already meets all of those constraints.
- TheLoneWolfling 11y agoI quote: > In particular with lazy-loading. Lazy loading != assigned in the constructor
- TheCoelacanth 11y agoYou can't lazy load a final variable. It has to be assigned in the constructor. If your point is that getting rid of null doesn't solve every single problem that exists, I agree. However, it in no way causes a degradation from the current status quo in nullable-by-default languages.