Exercise: Data class practice
- Create a data class for a
Person
with a name
and age
property of types String
and Int
. - Create a
Person
instance with name "John" and age 30. - Print the
Person
instance. - Create a copy of the
Person
instance with name "Jane". - Create a new
Person
instance with name "Jane" and age 30. - Check if the two
Person
instances are equal. - Print the
hashCode
of all the Person
instances. - Destructure the
Person
instance created using copy
(so the one with name "Jane") into two variables, and print values of those variables.
Once you are done with the exercise, you can check your solution here.
fun main() {
// Write your code here
}
Marcin Moskala is a highly experienced developer and Kotlin instructor as the founder of Kt. Academy, an official JetBrains partner specializing in Kotlin training, Google Developers Expert, known for his significant contributions to the Kotlin community. Moskala is the author of several widely recognized books, including "Effective Kotlin," "Kotlin Coroutines," "Functional Kotlin," "Advanced Kotlin," "Kotlin Essentials," and "Android Development with Kotlin."
Beyond his literary achievements, Moskala is the author of the largest Medium publication dedicated to Kotlin. As a respected speaker, he has been invited to share his insights at numerous programming conferences, including events such as Droidcon and the prestigious Kotlin Conf, the premier conference dedicated to the Kotlin programming language.