Kotlin 2 · Classes and types

Add a function to an existing type

An extension function is called like a member but defined outside the class.

fun String.isPalindrome() = this == reversed()

println("level".isPalindrome())

Official Kotlin 2 documentation

More classes and types commands

All classes and types commands · Kotlin 2 cheatsheet

Was this page helpful?