October 2018
Intermediate to advanced
370 pages
9h 15m
English
Kotlin allows us to specify the name of an argument when a class instance is created. This approach makes the object-creation more readable and it reduces the chance that we pass the wrong value to the parameters, especially when all of the parameters have the same data type.
To understand this concept, create a Person class and introduce a property, called weight, of the Double type:
class Person(val name: String, var age: Int = 0, var height : Double = 0.0, var weight : Double = 0.0)fun main(args: Array<String>) { val ali = Person(name = "Ali", age = 34, height = 6.1, weight = 78.5) println("name ${ali.name}, age ${ali.age}, height ${ali.height}, weight ${ali.weight}")}
Create a Person class object by assigning ...
Read now
Unlock full access