如何检查两个布尔值是否相等? [英] How to check if two boolean values are equal?

查看:735
本文介绍了如何检查两个布尔值是否相等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个方法,我可以在junit assertTrue()方法中调用它来比较两个布尔值以检查它们是否相等,返回一个布尔值。例如,类似这样的事情:

I need a method which I can call within the junit assertTrue() method which compares two booleans to check if they are equal, returning a boolean value. For example, something like this:

boolean isEqual = Boolean.equals(bool1, bool2);

如果不相等则返回false,如果相等则返回true。我已经检查了布尔类,但唯一接近的是 Boolean.compare(),它返回一个我无法使用的int值。

which should return false if they are not equal, or true if they are. I've checked out the Boolean class but the only one that comes close is Boolean.compare() which returns an int value, which I can't use.

推荐答案

== 运算符适用于布尔值。

The == operator works with booleans.

boolean isEqual = (bool1 == bool2);

(括号是不必要的,但有助于简化阅读。)

(The parentheses are unnecessary, but help make it easier to read.)

这篇关于如何检查两个布尔值是否相等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆