Kotlin Tutorial #10: Extension Functions and Properties

In the previous tutorial, you learned about lambdas and higher-order functions. Now let’s learn about extension functions and properties. Extensions let you add new functions and properties to existing classes without modifying them. This is one of Kotlin’s best features. You can add a toSlug() function to String or a secondOrNull() function to List — without changing the original class. In this tutorial, you will learn: Extension functions Practical extensions like String.toSlug() and List.secondOrNull() Extension properties Extensions on nullable types Companion object extensions Generic extensions Extension Functions An extension function adds a new function to an existing class. The class you extend is called the “receiver.” ...

March 22, 2026 · 8 min