首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

为何编译通过没有被强制检查错误

2013-08-04 
为何编译通过没有被强制检查异常public class E12_E8{public static void main(String[ ] args){f()}publ

为何编译通过没有被强制检查异常
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

热点排行