300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > java boolean空 Java检查布尔值是否为空

java boolean空 Java检查布尔值是否为空

时间:2022-05-28 02:22:51

相关推荐

java boolean空 Java检查布尔值是否为空

How do you check if a boolean is null or not? So if I know "hideInNav" is null. How do I stop

it from further executing? Something like the below doesn't seem to work but why?

boolean hideInNav = parent.getProperties().get("hideInNav", false);

String hideNavigation = hideInNav != null ? hideInNav : "";

解决方案

boolean can only be true or false because it's a primitive datatype (+ a boolean variables default value is false). You can use the class Boolean instead if you want to use null values. Boolean is a reference type, that's the reason you can assign null to a Boolean "variable". Example:

Boolean testvar = null;

if (testvar == null) { ...}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。