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

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.

主站蜘蛛池模板: 诸暨市| 黔南| 阿拉善右旗| 海门市| 霍山县| 无为县| 曲阳县| 衡水市| 东海县| 西藏| 洛南县| 东兰县| 济阳县| 张北县| 西峡县| 利川市| 黔东| 洞头县| 岳池县| 霍邱县| 桂阳县| 东安县| 墨玉县| 徐州市| 江达县| 巴林左旗| 正安县| 迁西县| 淳安县| 青神县| 金乡县| 大邑县| 眉山市| 巫溪县| 高雄县| 鄂托克旗| 辽源市| 沈阳市| 黄山市| 郧西县| 常德市|