摘自 Java Language Specification
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.
还有一种用法
If doSomething is overloaded, you need to cast the null explicitly to MyClass so the right overload is chosen:
详细见:
http://stackoverflow.com/questions/315846/why-null-cast
但是并没有所说的warning
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.
Object obj = null;
String str = (String) obj;
Integer a = (Integer) obj;
//int b = a;
//NullPointerException
还有一种用法
doSomething( (MyClass) null );
If doSomething is overloaded, you need to cast the null explicitly to MyClass so the right overload is chosen:
详细见:
http://stackoverflow.com/questions/315846/why-null-cast
但是并没有所说的warning