Exercise: Comparing Objects of Data Class
Refine your proficiency in Kotlin’s data class functionality by engaging in exercises that involve performing various operations on instances of this class.
We'll cover the following
Problem statement
Perform the following tasks to practice working with data classes in Kotlin:
Create a data class called
Person
with propertiesname
andage
.Instantiate a
Person
data class with thename
John andage
30.Print the details of the
Person
instance.Create a copy of the
Person
instance with thename
Jane.Instantiate a new
Person
with thename
Jane andage
30.Check if the two
Person
instances are equal.Print the
hashCode
of all thePerson
instances.Destructure the
Person
instance created usingcopy
(the one with thename
Jane) into two variables and print the values of those variables.
The actual output when running the provided code should be as follows:
Get hands-on with 1400+ tech skills courses.