Is null an Object?

If null were an Object, it would support the methods of java.lang.Object such as equals(). However, this is not the case - any method invocation on a null results in a NullPointerException.

And this is what the Java Language Specification has to say on this topic:

There is also a special null type, the type of the expression null, which has no name. Because the null type has no name, it is impossible to declare a variable of the null type or to cast to the null type. The null reference is the only possible value of an expression of null type. The null reference can always be cast to any reference type. In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.

I think this can be boiled down to "null is special".


According to the Java spec, null is a type that can be assigned to an object variable (as a value as noted in the comment). You cannot instantiate or create variables of this type though, you must use the literal null provided by the compiler.

Tags:

Java

Null