public class Test {
public static void greet(){
System.out.println("hello");
}
public static void main(String[] args){
((Test)null).greet();
}
}
会打印出:hello
但是原因是什么呢
public class Test {
public static void greet(){
System.out.println("hello");
}
public static void main(String[] args){
((Test)null).greet();
}
}
会打印出:hello
但是原因是什么呢
null的对象在内存中只是一个引用而已,你加了强类型转换,就成了Test类,