日期:2014-05-20  浏览次数:20688 次

为何编译通过没有被强制检查异常
public class E12_E8{
  public static void main(String[ ] args){
    f();
  }
  public static void f(){
    throw new NullPointerException();
  }
}

按照正常的编译
javac E12_E8.java
应该会编译不通过的,应该要写成这样才行的:
public static void f() throws NullPointerException{
    throw new NullPointerException();
  }
但是为何没有编译不通过呢???

------解决方案--------------------
NullPointerException是RuntimeException啦,
编译器不会对它做检查的
------解决方案--------------------
引用:
NullPointerException是RuntimeException啦,
编译器不会对它做检查的

+1