小编Art*_*jem的帖子

为什么在null引用上调用(静态)方法不会抛出NullPointerException?

我用Java编写了这个程序

public class Why {

  public static void test() {
    System.out.println("Passed");
  }

  public static void main(String[] args) {
    Why NULL = null;
    NULL.test();
  }

}
Run Code Online (Sandbox Code Playgroud)

我读到调用一个null对象的方法导致NullPointerException,但上面的程序没有?为什么是这样?我不正确地理解某事吗?

java null static nullpointerexception

49
推荐指数
1
解决办法
9709
查看次数

标签 统计

java ×1

null ×1

nullpointerexception ×1

static ×1