October 2018
Intermediate to advanced
370 pages
9h 15m
English
The data class provides a useful function called equals(), which compares each property of the two classes. It comes back as true if all the properties of both classes are the same, otherwise it comes back as false. Let's take a look at an example:
class Person(var name : String, var age : Int, var height : Double)fun main(args: Array<String>) { val abid = Person("Abid", 40, 6.0) val khan = Person("Abid", 40, 6.0) if(abid == khan) { println("Both Persons are same") } else { println("Different persons") }}
Read now
Unlock full access