Java 检查布尔值是否为空

编程入门 行业动态 更新时间:2024-10-26 14:28:09
本文介绍了Java 检查布尔值是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何检查布尔值是否为空?因此,如果我知道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 只能是 true 或 false 因为它是一个 原始数据类型(+一个 boolean 变量默认值值为 false).如果你想使用 null 值,你可以使用 Boolean 类.Boolean 是一种引用类型,这就是您可以将 null 分配给布尔变量"的原因.示例:

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 检查布尔值是否为空

本文发布于:2023-11-05 15:47:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561243.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   布尔值   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!