Operator Overloading
Learn how to overload operators in Kotlin.
We'll cover the following...
Kotlin operators under the hood
Kotlin has a wide range of operators. Under the hood, these existing operators translate into member function calls. Therefore, in Kotlin, a+b
is really a.plus(b)
, -a
is the a.unaryMinus()
call, and a++
is in fact a.inc()
.
Overloading Kotlin operators
Kotlin supports overloading existing operators (like +
, -
, + =
...