public class Main
{
public static void main(String []ar)
{
A m = new A();
System.out.println(m.getNull().getValue());
}
}
class A
{
A getNull()
{
return null;
}
static int getValue()
{
return 1;
}
}
我在SCJP的一本书中遇到了这个问题。代码输出的是1
,而不是预期的NPE。有人能解释一下为什么会这样吗?
https://stackoverflow.com/questions/10088078
复制相似问题