A function typically has its code wrapped in braces ({ }
).
However, simple functions can use "expression body" syntax, with a single
statement (preceded by =
) forming the body. When you call that function,
the statement is executed and whatever it evaluates to is what the function
returns.
This saves you a return
keyword. Plus, as with variables, Kotlin can infer
the data type that the function returns (in many cases), saving you having to
declare the type manually.
You can learn more about this in:
Tags: