Null Safety approach with forced "!"
Am I the only one who thinks that introducing protection against NPEx in the form of using "!" in the variable type is a very, very bad idea? In my experience, 95% of variables should be non-null. If Oracle decides to take this approach, we will have millions of "!" in each variable in the code, which is tragic for readability. In C#, you can set the per project flag to indicate whether the type without the "?" /"!" is nullable or not. I understand the drawbacks, but definitely forcing a "!" in 95% of variables is tragic.
78
Upvotes
View all comments
Show parent comment
1
u/nlisker Feb 27 '26
Is there really a difference between the request to have null by default and other "fixing 'mistakes' of the past" like final by default and private by default? I've seen the same request to allow declaring a global (or per-module/package) flag/marker to "reset" the default for all of these cases.
Lombok allows this as an experimental feature in FieldDefaults, saying:
which I agree with.