官术网_书友最值得收藏!

Logical operators

Logical operators include ! (NOT), && (AND), and || (OR), and obviously we use these to perform logical operations on operands. These methods are written for Boolean, so they expect Boolean operands:

scala> val log_not = !true
log_not: Boolean = false

scala> val log_or = true || false
log_or: Boolean = true

scala> val log_and = true && true
log_and: Boolean = true

Logical AND and OR are short-circuiting operators. It means that these are only evaluated till the result is undetermined. This is achievable in Scala even though operators are methods, because of a feature of function calls named by-name parameters. It allows us to pass parameters by name that get evaluated later on when required at the time of method call.

主站蜘蛛池模板: 观塘区| 靖远县| 深泽县| 三穗县| 元江| 满城县| 虹口区| 济源市| 漯河市| 临朐县| 贵溪市| 奉贤区| 云林县| 阳山县| 营口市| 河东区| 正宁县| 瓮安县| 赣榆县| 左云县| 中卫市| 慈利县| 瑞安市| 台中市| 太康县| 丹东市| 惠来县| 阿巴嘎旗| 潼南县| 敦化市| 瓮安县| 察雅县| 鹤壁市| 井陉县| 南溪县| 滦平县| 开封市| 邳州市| 康马县| 宣武区| 望江县|