【发布时间】:2010-09-14 17:06:03
【问题描述】:
我个人喜欢 exclusive or, ^, 运算符,因为它的简洁性在布尔检查的上下文中是有意义的。我更喜欢写作
if (boolean1 ^ boolean2)
{
//do it
}
比
if((boolean1 && !boolean2) || (boolean2 && !boolean1))
{
//do it
}
但我经常会从其他有经验的 Java 开发人员(不仅仅是新手)那里得到困惑,有时我会想知道它应该如何只用于按位运算。
我很好奇有关使用 ^ 运算符的最佳实践。
【问题讨论】:
标签: java conditional bitwise-operators logical-operators xor