Functions in Kotlin

Artem Diashkin
LITSLINK
Published in
5 min readMar 26, 2021

--

In this article we will take a look at the features of a functions in Kotlin: declarations, named arguments and default params, extensions, infix, etc

Function declaration

We will begin with simple examples of how we can declare functions in Kotlin:

  • you can declare a simple function with brackets or you can declare a simplified notation if your function logic is chained:
  • if you set a question mark ? after a function argument, it means that it can be null;
  • if you function returns nothing/void you can set a return type of your function as Unit. In Kotlin Unit = void;

⚠️ NOTE: You can use your Kotlin functions from *.kt files inside of *.java files. If we will decompile our previous example we will see that our functions were declared as static, so…

--

--