here null means, reference not pointing to any object in the heap. so for any type of object reference we can say that it is not pointing to any object. hope helps.
1- It can be cast to any reference type, but not to any primitive type such as int or boolean.
2- It is impossible to cast to the null type or declare a variable of this type.
I think the issue that the OP is having is trying to classify what is the type of "null" -- as it seems to have some contradictory behaviors.
IMHO, I think it is easier to think of null as a literal, that can be cast to any object type, can be assigned to any object type, but when used with the instanceof operation, it always return false. I don't think it is correct to think of it as an object (or not an object). I think it may be best to think of it as a literal that has special behaviors.
Henry
Ernest Friedman-Hill
,
author and iconoclast
staff
Note that "instanceof" is generally irrelevant to the question of whether code will compile, as "instanceof" is a runtime operation (true, the compiler will reject impossible uses of instanceof between incompatible types.) In the case of null, though, the key thing is, as has been pointed out, that you can legally cast null to any reference type, and code is compiled based only on reference types (or "compile-time types.") The runtime type of an object, or the presence or absence of an object at all, has nothing whatsoever to do with compilation.
Post by:autobot
That feels good. Thanks. Here's a tiny ad:
a bit of art, as a gift, that will fit in a stocking