9 Operator overloading and other conventions

This chapter covers

  • Operator overloading
  • Conventions: special named functions supporting various operations
  • Delegated properties

Kotlin has a number of features where specific language constructs are implemented by calling functions that you define in your own code. You already may be familiar with these types of constructs from Java, where objects that implement the java.lang.Iterable interface can be used in for loops and objects that implement the java.lang.AutoCloseable interface can be used in try-with-resources statements.

In Kotlin, such features are tied to functions with specific names (and not bound to some special interfaces in the standard library, like they are in Java). For example, ...

Get Kotlin in Action, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.