Postfix operators [] . (parameters) expression++ expression--
Unary prefix operators ++expression --expression +expression -expression ~ !
Unary prefix creation and cast new (type)
Multiplicative * / %
Additive + -
Shift << >> >>>
Relational < <= > >= instanceof
Equality == !=
Bitwise/logical AND &
Bitwise/logical XOR ^
Bitwise/logical OR |
Conditional AND && //here
Conditional OR || //here
Conditional ?:
Assignment = += -= *= /= %= <<= >>= >>>= &= ^= |=
这是 kalid A Mughal & Rasmussen 书中发表的运算符优先级
根据本书,&&
的优先级高于 ||
,但以下代码
if(true&&false||true)
{
System.out.println("yes");
}
此代码打印“yes”
。表示首先执行 "||"
这本书有错吗?或者我的解释错误。
最佳答案
我猜你的解释是错误的。由于 &&
具有更高的优先级,因此求值顺序为
(true && false) || true
这是
false || true -> true
关于java - && 和 || 的优先级java中的运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12010362/