而不是写:
if (someexpression) { return true;} else { return false;}写:
return someexpression;
至于表达式本身,是这样的:
boolean atLeastTwo(boolean a, boolean b, boolean c) { return a ? (b || c) : (b && c);}或此(无论您觉得更容易掌握):
boolean atLeastTwo(boolean a, boolean b, boolean c) { return a && (b || c) || (b && c);}它测试
a和
b准确一次,
c最多一次。
参考文献
- JLS 15.25条件运算符?:



