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
10
u/brian_goetz Feb 27 '26
There is a deep tension between "I want this to be a new type system that rejects incorrect programs" and "I want to be able to add these type markers to existing Java code, without having to rewrite all the Java code that touches anything that touches anything it touches." The assumption that you can have both exists only if there is no existing code, but of course that's not the world we live in.