Extensions Function in Kotlin

Save

What are Extensions Function?

Extensions function in kotlin provide the ability to extend the class with new functionality without extends the class. Extensions function do not modify class they extend the class and insert new functionality in the class.

How to write extension functions?

Let’s begin with very basic we know that to show a simple Toast in an Activity we have to write boilerplate code we have to pass context, message and the duration in makeText() method. Then the question arises how extension function can make our life easy so let’s start with Toast now I going to show you how we can extend the Activity class and add new functionality to just show toast anywhere in activity all we have to do just call showToast() method and pass the message.

In the above example, we have seen how extension function we can write to just show a Toast and call it in any activity in our application.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.

Hussein Zawia

Hussein Zawia

Co-founder, 24Dokan

Talk to Sales

Global

Live Chat
Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home