一个方法里面过长, 把部分代码提取出来后, 发现发了NullPointerException异常.DEBUG了半天, 才发现, 原来是Integer做祟.
类似代码如:
public test1(Integer i){
System.out.println(i);
}
提取后的代码:
public test1(Integer i) {
test2(i);
}
public test2(int i) {
System.out.println(i);
}
第二部分代码当i是空时, 会报NullPointerException异常, 反编译了一下, 原来,JAVA
在自动拆箱时调用的是intValue()方法, null的i调用intValue()方法就会报nullException.
类似代码如:
public test1(Integer i){
System.out.println(i);
}
提取后的代码:
public test1(Integer i) {
test2(i);
}
public test2(int i) {
System.out.println(i);
}
第二部分代码当i是空时, 会报NullPointerException异常, 反编译了一下, 原来,JAVA
在自动拆箱时调用的是intValue()方法, null的i调用intValue()方法就会报nullException.