October 2018
Intermediate to advanced
370 pages
9h 15m
English
Functions can receive parameters and return values as a result. See the following example, which takes a value as a parameter and returns the result:
fun myFun(message : String) : String { return "Hello from $message" } fun main (args: Array<String>){ val result = myFun("Author") println(result)}
This function takes a string as a parameter and returns a string value. Like other programming languages, Kotlin also uses the return keyword to return a value from a function. The return value must be the same as the return type defined in the function signature:
fun add(i: Int, j: Int): Int
If a return type of the function is integer, the return statement must be an integer, otherwise the compiler will ...
Read now
Unlock full access