以下代码中的toString方法抛出NullPointerException,但printl打印后调用null.为什么他们没有相同的结果?THL
package exceptionsNullPointer;
public class NPArrays {
public static void main(String[] args) {
String[] laces = new String[2];
// this line throws NullPointerException
System.out.println(laces[1].toString());
// this line prints null
System.out.println(laces[1]);
}
}
Run Code Online (Sandbox Code Playgroud)