- 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.
推薦閱讀
- GAE編程指南
- Mastering JavaScript Object-Oriented Programming
- JavaScript修煉之道
- Java從入門到精通(第5版)
- Java程序員面試算法寶典
- Python Geospatial Development(Second Edition)
- Cassandra Data Modeling and Analysis
- Learning Python Design Patterns
- Building Machine Learning Systems with Python(Second Edition)
- Qt5 C++ GUI Programming Cookbook
- FFmpeg開發實戰:從零基礎到短視頻上線
- App Inventor 2 Essentials
- Python硬件編程實戰
- 人人都能開發RPA機器人:UiPath從入門到實戰
- Java RESTful Web Service實戰