-
Notifications
You must be signed in to change notification settings - Fork 23
What are extension functions
Devrath edited this page Mar 6, 2024
·
1 revision
- Extension functions are a feature in Kotlin that allows you to add new functions to existing classes without modifying their source code.
- This means you can extend the functionality of classes, including standard library classes, third-party classes, or your custom classes, without the need for inheritance or altering the original class.
Code
fun main(args: Array<String>) {
val result = "Panda".addCustomString()
println(result)
}
fun String.addCustomString() : String {
val customString = " Horray!!"
return this.plus(customString)
}
Output
Panda Horray!!