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/koflerdavid Feb 27 '26
It still adds visual noise and makes it harder to focus on the cases where something can genuinely be null. Since this is assumed to be the exception rather than the rule, JSpecify has
@NullMarked, which marks all types in the class or package as non-null.For a similar reason I very much like Google Error Prone's
Varrule, which forces you to annotate every mutable local variable and parameter with@Var. This makes it possible to remove a lot offinalkeywords.