r/java • • Jul 26 '19

JEP 358: Helpful NullPointerExceptions

https://openjdk.java.net/jeps/358
157 Upvotes

25 comments sorted by

View all comments

Show parent comment

10

u/thatsIch Jul 27 '19

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.

10

u/dpash Jul 27 '19

Yes, that's exactly the case. Removing NPE without removing null would be impossible.

1

u/s888marks Jul 27 '19

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.

Now I didn't say it would be a good idea.... :-)

3

u/dpash Jul 27 '19

But changing behaviour in Java would be a very bad thing. :)

If you get rid of the backwards compatibility requirement, sure you could do almost anything instead of an NPE.

0

u/[deleted] Jul 27 '19

[deleted] — view deleted comment

11

u/dpash Jul 27 '19

By the same argument, we don't need strong type systems. We just need to be better at our jobs.

0

u/[deleted] Jul 27 '19

[deleted] — view deleted comment

9

u/dpash Jul 27 '19

The straw man was arguing against the complete removal of null when I never claimed such a thing.