关于 Java 中涉及 Null 的三元缩写的澄清
此站点:Java 中 null 常量的信息 指出以下两个语句是同义词:
if(PossibleNullVariable!=null)PossibleNullVariable.Action();
PossibleNullVariable!.Action();
此外,此站点:关于在 Java 中避免 null 检查的信息 指出这两个声明是同义词:
String str = getStringMayBeNull()!=null?getStringMayBeNull():"";
String str = getStringMayBeNull() ?: “”;
请问我可以澄清一下吗?感谢您抽出时间。 (:
This site: Information on the null constant in Java states that the following two statements are synonymous:
if(PossibleNullVariable!=null)PossibleNullVariable.Action();
PossibleNullVariable!.Action();
Also, This site: Information on avoiding null checks in Java states that these two statements are synonymous:
String str = getStringMayBeNull()!=null?getStringMayBeNull():"";
String str = getStringMayBeNull() ?: “”;
Could I please get some clarification please? Thank you for your time. (:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些都是文章作者提出的建议,作为处理
null
的更好方法。目前两者都不是 Java 语言。Both of those are suggestions given by the authors of the articles as better ways of dealing with
null
. Neither are currently in Java.