Java检查布尔值是否为空 [英] Java check if boolean is null
本文介绍了Java检查布尔值是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查布尔值是否为null?因此,如果我知道"hideInNav"为空.我怎么停 它从进一步执行?像下面这样的东西似乎不起作用,但是为什么呢?
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) { ...}
这篇关于Java检查布尔值是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文