January 2018
Intermediate to advanced
434 pages
14h 1m
English
We will be using the copy method, which takes in named arguments and creates a copy of the object with changed values of named arguments. Let's look at an example:
data class Student(val name:String,val roll_number:String,var age:Int)fun main(args: Array<String>) { var studentA= Student("Aanand Roy", "2013001", 21) var olderStudentA=studentA.copy(age = 25) println(olderStudentA.toString())}//Output: Student(name=Aanand Roy, roll_number=2013001, age=25)
Read now
Unlock full access