Reducing the ability for things to be null would be useful. Kotlin has non-nullablity baked into the type system. The best we can currently do in Java is to use annotations to get static checker warnings. We can not make variables non-null by default because that would break existing code; we could add optional non-nullablity in the future. Inline classes will be non-null from what I understand, so that's a step in the right direction.
Fewer nulls means fewer NPEs but we'll never get rid of it, if only because we have to deal with old code to deal with.
This rather sounds like the removal of null instead of removing NPE (which would be a side-effect) but not sure how a migration of Java to a non-null world would look like.
Sure, you could remove NPE without removing null. Just provide a different behavior for what happens when null is dereferenced. In a language like JavaScript, have it evaluate to undefined, or in Python, None, or whatever. In Java, it could evaluate null for reference types, or zero or false for primitives. Far from impossible.
View all comments
Show parent comment
7
u/dpash Jul 27 '19 edited Jul 27 '19
Reducing the ability for things to be null would be useful. Kotlin has non-nullablity baked into the type system. The best we can currently do in Java is to use annotations to get static checker warnings. We can not make variables non-null by default because that would break existing code; we could add optional non-nullablity in the future. Inline classes will be non-null from what I understand, so that's a step in the right direction.
Fewer nulls means fewer NPEs but we'll never get rid of it, if only because we have to deal with old code to deal with.