3 回答

TA貢獻1784條經驗 獲得超9個贊
&&
||
&
|
false && ...
-不需要知道右手是什么,結果必須是 false
true || ...
-不需要知道右手是什么,結果必須是 true
public boolean longerThan(String input, int length) { return input != null && input.length() > length;}public boolean longerThan(String input, int length) { return input != null & input.length() > length;}
&
NullPointerException
input
null
false

TA貢獻1877條經驗 獲得超1個贊
集合A使用短路布爾運算符.
在布爾運算符的上下文中,“短路”的意思是,對于一組布爾函數b1、b2、.、bn,一旦第一個布爾值為真(X)或false(&),短路版本就會停止計算。
例如:
// 2 == 2 will never get evaluated because it is already clear from evaluating
// 1 != 1 that the result will be false.
(1 != 1) && (2 == 2)
// 2 != 2 will never get evaluated because it is already clear from evaluating
// 1 == 1 that the result will be true.
(1 == 1) || (2 != 2)

TA貢獻1836條經驗 獲得超3個贊
添加回答
舉報