Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 126.96.36.199 release ready!
Updated 31 October 2021
In this blog, we are going to learn about functions in kotlin it is the most beautiful thing in kotlin.
In this, we will learn about the Extention function and also we will cover some basic stuff about the functions in kotlin.
There is a major difference between java functions and kotlin functions. We can not provide the default values of any arguments of functions in java if have a function that takes two arguments then we have to provide both of arguments to call that function but in the case of kotlin we have the facility to provide the default value.
Function parameters can have default values, which are used when you skip the corresponding argument. This reduces the number of overloads:
A default value is defined using = after the type.
There is also a cool thing in kotlin functions. We can assign the value of an argument by just calling its name in the argument and assigning its value. The benefit of this approach is we don’t have to remember the sequence of that particular argument we just have to name that parameter and assign it value. It will automatically refer the value to the named argument. Below is an example of how we can use the named argument.
Kotlin provides the ability to add and modify some new functionality in classes no matter it is a third-party class or a predefined class.
like we have a list and we want to add a new function in it that will return us the sum of the list that list have contained Integer values in it.
We will get 20 as the sum of myList.
Hope this blog will help you to understand the Extension functions and the basic concepts of kotlin functions.
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.