November 2018
Intermediate to advanced
388 pages
9h 5m
English
The fun keyword is used to define functions in Kotlin. In this section, we'll discuss writing a function, type inference, and specifying the return type.
In the following example, we create a function that takes two arguments of the String type and prints them to the console.
Consider the following code for 6_Function.kts:
fun welcome(name:String, msg:String) { println("$msg $name")}welcome("Bob", "hello")
Note that we used string template to print the values without concatenating string literals.
The output of the preceding code as follows:

This is a simple example of creating a function and invoking it. Now, let's create a function ...
Read now
Unlock full access