15.4 Single Expression Functions
When a function contains a single expression, it is not necessary to include the braces around the expression. All that is required is an equals sign (=) after the function declaration followed by the expression. The following function contains a single expression declared in the usual way:
fun multiply(x: Int, y: Int): Int {
return x * y
}
Below is the same function expressed as a single line expression:
fun multiply(x: Int, y: Int): Int = x * y
When using single line expressions, the return type may be omitted in situations where the compiler is able to infer the type returned by the expression making for even more compact code:
fun multiply(x: Int, y: Int) = x * y