Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 为什么空引用打印为“空”
这是在 java API 中指定的。不知这是为了兼容以前的java版本,还是有其他一些重要的原因。
转换为 aString时,null包含在消息中通常比抛出 a 更有用,NullPointerException因为您至少可以看到消息的其余部分。差异可能是一个务实的决定。
String
null
NullPointerException