Extension Functions
Learn about the concept of extension functions in Kotlin.
Introduction
With the help of extension functions, classes can be extended, even if they are final
, like String
.
Extension functions allow us to declare functions outside a class, and yet their call looks like that of a method of that given class.
Example
Suppose that, in a project, it is necessary to calculate the square
of an integer.
A suitable function for this is a quick write, as shown here:
Get hands-on with 1400+ tech skills courses.