Extension Functions

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 1200+ tech skills courses.