Operator overloading
Operator overloading
Kotlin allows us to provide implementations for a predefined set of operators on our types. These operators have fixed symbolic representation (like +
or *
) and fixed precedence. To implement an operator, we provide a member function or an extension function with a fixed name, for the corresponding type, i.e. left-hand side type for binary operations and argument type for unary ones. Functions that overload operators need to be marked with the operator
modifier.
Conventions
Here we describe the conventions that regulate operator overloading for different operators.