A mindless query arising from Java's less known data type 'null'.
Would somebody be able to clarify whether or not 'null' is a literal reserved by the Java language and thus the disparity between it satisfying as primitive data type and a digital value?
NULL default_object_value; // a Syntax error
NULL acct_balance_at_westbank = null; // Another Syntax error
String aStrokeOfLuck = null; // a feasible variable declaration & assignment
According to JLS 4.1, there actually is a type for
null.So.
nullis a literal reserved by the Java language.nulldenotes a value not a type.The type of
nullcannot be named. Hence your failed attempts to do that.(I don't even think there is a reflective
java.lang.Classrepresentation for the null type ...)The JLS says that the type of
nullis neither a primitive type or a reference type.Various contexts allow
nullto be converted to the null value of any reference type; e.g.I imagine that there is some technical reason that they have chosen to specify the null type this way. Maybe this makes other parts of the spec simpler. I don't know. And unless you are a black-belt type theoretician, the why question is most likely irrelevant.
I cannot make sense of that part of your question.
As mentioned in the comments,
NULLis just an ordinary identifier. The Java class libraries don't declare a class with that name, and as such you will most likely get an unresolved symbol error. You could declare one for yourself, but thatNULLclass will not (and cannot) denote the null type as far as the Java compiler or runtime is concerned.