- Learning Scala Programming
- Vikash Sharma
- 126字
- 2021-06-30 19:07:52
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.
推薦閱讀
- Dependency Injection in .NET Core 2.0
- C/C++常用算法手冊(第3版)
- 單片機應用技術
- 零基礎學Java程序設計
- 正則表達式經典實例(第2版)
- C#應用程序設計教程
- 編程改變生活:用Python提升你的能力(進階篇·微課視頻版)
- Nagios Core Administration Cookbook(Second Edition)
- DB2SQL性能調優秘笈
- Java 9 with JShell
- Android應用程序設計
- 循序漸進Vue.js 3前端開發實戰
- HTML5 and CSS3:Building Responsive Websites
- Spring Microservices
- LiveCode Mobile Development Hotshot