Operator Overloading

This Atom is Under Construction

In the context of computer programming, overloading means “adding an extra meaning to something that already exists.”

Operator overloading allows you to take an operator like + and give it meaning for your new type, or an extra meaning for an existing type.

Operator overloading has a tumultuous past. It was popularized in C++, but because C++ had no garbage collection, writing overloaded operators was difficult. As a result, the early Java designers deemed operator overloading “bad” and didn’t allow it in Java, even though Java’s garbage collection would have made it relatively easy. The simplicity of operator overloading when supported by garbage-collection was demonstrated in the Python language, which constrained you to a limited (familiar) set of operators (as did C++). Scala then experimented with allowing you to invent your own operators, causing some programmers to abuse this feature and create truly incomprehensible code. Kotlin learned from all these languages, and has simplified the process of operator overloading but restricts your choices to a reasonable and familiar set of operators. In addition, the rules of operator precedence cannot be changed.

End of sample. See AtomicKotlin.com for full early-access book.

Previous          Next

©2018 Mindview LLC. All Rights Reserved.