【发布时间】:2014-11-01 11:30:16
【问题描述】:
String s = null;
s = s + "hai";
System.out.println(s);
输出:
nullhai
认为这会让我 NPE。
背后的基本逻辑是什么
- 在使用
+(连接)时不抛出 NPE - 使用
.时抛出 NPE
【问题讨论】:
-
语言规范将其定义为这样工作;见:docstore.mik.ua/orelly/java/fclass/ch02_03.htm
标签: java string nullpointerexception