如何将正确的表达式写入布尔值结果? (无法从布尔值转换为布尔值)

发布于 2025-01-08 07:27:07 字数 534 浏览 7 评论 0原文

我在使用应导致在 iReport 中显示或隐藏带区的表达式时遇到困难。

这些是我拥有的变量:

Integer mainGroupInt = Integer.valueOf(5);
Integer subGroupInt = Integer.valueOf(5);
Boolean showDetailGroup = Boolean.valueOf(false);

结果必须是布尔值,因此我尝试了以下操作:

mainGroupInt.intValue() != 0 && subGroupInt.intValue() != 0)) || (mainGroupInt.intValue() != 0 && showDetailGroup)

因此这不起作用,我收到以下错误:

将boolean类型的表达式装箱为Boolean

我想太多了,但我无法解决它。

感谢您的帮助。

I am experiencing difficulties with an expression that should result in showing or hiding a band in an iReport.

These are variables that I have:

Integer mainGroupInt = Integer.valueOf(5);
Integer subGroupInt = Integer.valueOf(5);
Boolean showDetailGroup = Boolean.valueOf(false);

The result must be a Boolean, so I tried the following:

mainGroupInt.intValue() != 0 && subGroupInt.intValue() != 0)) || (mainGroupInt.intValue() != 0 && showDetailGroup)

This is thus not working, I get the following error:

The expression of type boolean is boxed into Boolean

I'm overthinking this one but I cannot solve it.

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

涫野音 2025-01-15 07:27:07

您在寻找...

showDetailGroup = Boolean.valueOf( (mainGroupInt.intValue() != 0 && subGroupInt.intValue() != 0) || 
                                   (mainGroupInt.intValue() != 0 && showDetailGroup.booleanValue()) )

如果不是,我不明白您的问题。上面的代码返回一个表示 boolean 表达式的值的 Boolean。请参阅 Java Boolean.valueOf ()Boolean.booleanValue() 文档。

Are you looking for...

showDetailGroup = Boolean.valueOf( (mainGroupInt.intValue() != 0 && subGroupInt.intValue() != 0) || 
                                   (mainGroupInt.intValue() != 0 && showDetailGroup.booleanValue()) )

If not, I don't understand your question. The above code returns a Boolean representing the value of the boolean expression. See Java Boolean.valueOf() and Boolean.booleanValue() docs.

心在旅行 2025-01-15 07:27:07

布尔值(大写 B )不能在不拆箱的情况下在布尔表达式中使用。

如果您想消除警告,请通过调用 booleanValue 函数将 Boolean 转换为原始类型(这是拆箱时幕后发生的事情):

mainGroupInt.intValue() != 0 && showDetailGroup.booleanValue( )

Boolean ( with capital B ) cannot be used in the boolean expressions without unboxing it.

If you want to silence the warning, convert Boolean to primitive type by calling booleanValue function (this is what's happening behind the scene with unboxing):

mainGroupInt.intValue() != 0 && showDetailGroup.booleanValue( )
回眸一笑 2025-01-15 07:27:07

Boolean 和 Integer 是原语 boolean 和 int 的包装类。如果必须通过函数引用传递变量,则应将变量更改为 boolean 和 int,并稍后将它们包装起来。

Boolean and Integer are wrapper classes for the primitives boolean and int. You should change your variables to boolean and int and wrap them up later if you must pass them by reference to a function.

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