...

/

Introduction to Extensions

Introduction to Extensions

Learn about extension functions in Kotlin, how to define and use them to extend classes, and their similarities to member functions.

Introduction to class members

The most intuitive way to define methods and properties is inside classes. Such elements are called:

  • Class members

  • Member functions

  • Member properties

Press + to interact
class Telephone(
// member property
val number: String
) {
// member function
fun call() {
print("Calling $number")
}
}
fun main() {
// Usage
val telephone = Telephone("123456789")
println(telephone.number) // 123456789
telephone.call() // Calling 123456789
}

Introduction to extension functions

...