java中的逻辑异或运算符是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26390480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:25:07  来源:igfitidea点击:

What is the logical xor operator in java?

javaboolean-logicxor

提问by Pokechu22

In java, there is a logical OR operator (||) and a logical AND operator (&&). Is there a logical XORoperator? I tried ^^but it does not work.

在 Java 中,有一个逻辑 OR 运算符 ( ||) 和一个逻辑 AND 运算符 ( &&)。是否有逻辑异或运算符?我试过了,^^但它不起作用。

采纳答案by NPE

The logical XOR operator does exist in Java and is spelled ^.

Java 中确实存在逻辑 XOR 运算符,拼写为^

To get the terminology right, in Java:

为了使术语正确,在 Java 中:

  • &, |and ^are called bitwiseor logicaloperators, depending on the types of their arguments;
  • &&and ||are called conditionaloperators.
  • &,|^被称为按位逻辑运算符,这取决于它们的参数类型;
  • &&||被称为条件运算符。

For details, see JLS § 15.22. Bitwise and Logical Operatorsonwards.

有关详细信息,请参阅JLS § 15.22。位运算符和逻辑运算符

There is no direct equivalent for &&and ||for XOR. The only reason &&and ||exist as separate operators from &and |is their short-circuiting behaviour(that's why they're called "conditional"), and XOR cannot be short-circuited.

没有直接的等价物&&,并||进行XOR。唯一的原因,&&||作为独立的运营商存在的&,并|为他们的短路行为(这就是为什么他们是所谓的“条件”),和XOR不能短路。