Extension functions

The extension functions in Kotlin provide an easy way to add new functionality to an existing API in a non-intrusive way. Often, they are used to eliminate the need to write special utility or helper classes. They make the code more idiomatic and readable.

Here is an example of where an extension function is added to the library class (java.lang.String) to check if the string is an email or not:

    fun String.isEmail(): Boolean {      // Logic to check if it's a email    }

This function will behave as a part of the String class, so you can achieve it as follows:

    "kotlin.blueprints@packt.com".isEmail()

Where can the extension functions be used in the context of Spring Boot?

A case in point is where our Kotlin code needs to call ...

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.