Student s;
System.out.println(s.toString());
编译不过,因为s没有initialized过。Student s = null;
System.out.println(s.toString());
编译过,但是吐NullPointerException.会带来什么后果?不会有什么后果,只是程序跑不动。
怎么解决?判断先。
System.out.println(s == null ? "[NULL]" : s.toString());
System.out.println(s.toString());
编译不过,因为s没有initialized过。Student s = null;
System.out.println(s.toString());
编译过,但是吐NullPointerException.会带来什么后果?不会有什么后果,只是程序跑不动。
怎么解决?判断先。
System.out.println(s == null ? "[NULL]" : s.toString());
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货