Kotlin中按位运算符的计算顺序

7

我找不到关于 Kotlin 位运算符计算顺序的信息。它是否与 Java 相同,还是从左到右计算而没有任何优先级?

1个回答

10

andorxor等位运算中缀函数并非严格意义上的运算符,它们的执行顺序与其他中缀函数相同,即从左到右,因此以下两行代码是等价的:

a or b and c or d and e

(((a or b) and c) or d) and e

Also note that the precedence of the infix functions is lower than that of operators:

1 + 2 and 3 + 4

(1 + 2) and (3 + 4)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接