January 2018
Intermediate to advanced
414 pages
10h 29m
English
We may have a function written that returns a value, such as:
fun lower(name : String) : String { val lower : String = name.toLowerCase() return "$name in lower case is: $lower"}
Here, we are explicitly indicating the type of the result of the function and the internal variable that we use inside.
In Kotlin, we could infer the type of the variable:
fun lower(name : String): String { val lower = name.toLowerCase() return "$name in lower case is: $lower"}
And even the return type of our function could be inferred:
fun lower(name : String) = "$name in lower case is: ${name.toLowerCase()}"
This will be extremely useful as the code that we created with the inferred type did not need to change if we change the type it uses. Let's ...
Read now
Unlock full access