Read complete story

Extensions Function in Kotlin

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.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close