Java是否在知道布尔结果后评估剩余条件? [英] Does Java evaluate remaining conditions after boolean result is known?
本文介绍了Java是否在知道布尔结果后评估剩余条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
也就是说,如果我有一个评估多个条件的陈述,比如说'或'这样的陈述..
That is, if I have a statement that evaluates multiple conditions, in say a 'or' statement like so..
if(isVeryLikely() || isSomewhatLikely() || isHardlyLikely())
{
...
}
如果 isVeryLikely()
在运行时返回true,那么 isSomewhatLikely()
和 isHardlyLikely()
执行?如果不是方法而是静态布尔值呢?
In the case that isVeryLikely()
returns true at runtime, will isSomewhatLikely()
and isHardlyLikely()
execute? How about if instead of methods they were static booleans?
推荐答案
||
和&&
运营商正在短路。
true || willNeverExecute();
false && willNeverExecute();
这篇关于Java是否在知道布尔结果后评估剩余条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文