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个赞
添加回答
举报