February 2018
Intermediate to advanced
350 pages
7h 35m
English
Unary operators don't have parameters and act directly in the dispatcher.
We can add a not operator to the Wolf class:
operator fun Wolf.not() = "$name is angry!!!"!talbot // talbot.not()
The following table will show you all the possible unary operators that can be overloaded:
|
Operator |
Equivalent |
Notes |
| +x | x.unaryPlus() | |
| -x | x.unaryMinus() | |
| !x | x.not() | |
| x++ | x.inc() | Postfix, it must be a call on a var, should return a compatible type with the dispatcher type, shouldn't mutate the dispatcher. |
| x-- | x.dec() | Postfix, it must be a call on a var, should return a compatible type with the dispatcher type, shouldn't mutate the dispatcher. |
| ++x | x.inc() | Prefix, it must be a call on a var, should return a compatible type ... |
Read now
Unlock full access