Usually a function should declare it as a return type. But if some functions consist of a single expression, we can omit the curly braces and return type and use the character =before the expression, and not with the return keyword. This type of function is called Single Expression Functions .
Example:
fun add(a: Int, b: Int): Int {
return a + b
}
This code can be simplified to:
fun add(a: Int, b: Int) = a + b
The compiler will oblige you to do this.
source
share