On Mon, Sep 24, 2012 at 5:23 AM, Regan Heath <regan@netmail.co.nz> wrote:
What I've noticed looking at Java code written by others is that null as a possible state is ignored by the vast bulk of the code, which is completely the opposite when reviewing C/C++ code where null is checked for and handled where applicable.  I think it's a mindset thing brought on by the language, or how it's taught, or something.  It seems to me that Java would have benefited from non-null references :p


Just because (from your experience) null checks are more prevalent in C or C++ compared to Java does not mean that any of those languages could not benefit from non-nullable types. The entire point is to statically prove that a certain reference/pointer cannot be null. You are better able to reason about the code, and it is done at compile time with no run time overhead. Furthermore, you avoid the possibility of forgetting to put in the checks in the first place.

--
Ziad