February 2018
Intermediate to advanced
350 pages
7h 35m
English
In Kotlin, function parameters can have default values. For the Programmer, the favouriteLanguage and yearsOfExperience data classes have default values (remember that a constructor is a function too):
data class Programmer(val firstName: String, val lastName: String, val favouriteLanguage: String = "Kotlin", val yearsOfExperience: Int = 0)
So, Programmer can be created with just two parameters:
val programmer1 = Programmer("John", "Doe")
But if you want to pass yearsOfExperience, it must be as a named parameter:
val programmer2 = Programmer("John", "Doe", 12) //Errorval programmer2 = Programmer("John", "Doe", yearsOfExperience = 12) //OK
You can still pass all parameters if you want to, but they must be provided in the ...
Read now
Unlock full access