为什么java将空字符串打印为“null”而不是抛出 NullPointerException?

发布于 2024-12-05 04:11:02 字数 240 浏览 0 评论 0原文

可能的重复:
为什么 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落日海湾 2024-12-12 04:11:02

转换为 String 时,消息中包含 null 通常比抛出 NullPointerException 更有用,因为您至少可以看到消息的其余部分信息。这种差异可能是一个务实的决定。

When converting to a String, having null in the message is often more useful than throwing a NullPointerException as you can at least see the rest of the message. The difference is likely to be a pragmatic decision.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文