As I understood null
is instance of T
for all reference type T
.
Question 1. What's defenition of null
? How does null
represents in memory?
Consider the following case: We defined class
public class MyClass{
Integer i;
}
Now null
can be cast to MyClass
, but I don't explicitly define that.
Question 2. From what compiler will be know that null
can be cast to MyClass
?
Formally, null
is a singleton member of the null
type, which is defined to be the subtype of every other Java type.
null
is a reference type and its value is the only reference value which doesn't refer to any object. Therefore there is no representation of null
in memory. The binary value of a reference-typed variable whose value is null
is simply zero (all zero bits). Even though this is not explicitly specified, it follows from the general initialization semantics of objects and any other value would cause major problems to an implementation.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments