为什么java将空字符串打印为“null”而不是抛出 NullPointerException?
可能的重复:
为什么 null 引用打印为“null”
这是java中指定的API。我想知道这是为了兼容以前版本的java,还是有其他一些重要原因。
Possible Duplicate:
Why does null reference print as “null”
This is specified in java API. I wonder if this is for compatibility with previous versions of java, or has some other important reasons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
转换为
String
时,消息中包含null
通常比抛出NullPointerException
更有用,因为您至少可以看到消息的其余部分信息。这种差异可能是一个务实的决定。When converting to a
String
, havingnull
in the message is often more useful than throwing aNullPointerException
as you can at least see the rest of the message. The difference is likely to be a pragmatic decision.