August 2017
Intermediate to advanced
440 pages
10h
English
Parameters in Kotlin functions are declared using Pascal notation, and the type of each parameter must be explicitly specified. All parameters are defined as read-only variables. There is no way to make parameters mutable, because such behavior is error-prone and in Java it was often abused by programmers. If there is a need for that, then we can explicitly shadow parameters by declaring local variables with the same name:
fun findDuplicates(list: List<Int>): Set<Int> {
var list = list.sorted()
//...
}
This is possible, but it is treated as bad practice, so a warning will be displayed. A better approach is to name parameters by the data they provide and variables by the purpose they serve. These names should then be different ...
Read now
Unlock full access