如何将正确的表达式写入布尔值结果? (无法从布尔值转换为布尔值)
我在使用应导致在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在寻找...
如果不是,我不明白您的问题。上面的代码返回一个表示
boolean
表达式的值的Boolean
。请参阅 Java Boolean.valueOf () 和 Boolean.booleanValue() 文档。Are you looking for...
If not, I don't understand your question. The above code returns a
Boolean
representing the value of theboolean
expression. See Java Boolean.valueOf() and Boolean.booleanValue() docs.布尔值(大写 B )不能在不拆箱的情况下在布尔表达式中使用。
如果您想消除警告,请通过调用 booleanValue 函数将 Boolean 转换为原始类型(这是拆箱时幕后发生的事情):
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):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.