Question: In Kotlin: Learn about classes, properties and data classes and then rewrite the following Java code to Kotlin: public class Person { private final String

In Kotlin: Learn about classes, properties and data classes and then rewrite the following Java code to Kotlin: public class Person { private final String name; private final int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } } Afterward, add the data modifier to the resulting class. Learn about classes, properties and data classes and then rewrite the following Java code to Kotlin: public class Person { private final String name; private final int age; public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public int getAge() { return age; } } Afterward, add the data modifier to the resulting class. The compiler will generate a few useful methods for this class: equals/hashCode, toString, and some others. class Person fun getPeople(): List { return listOf(Person("Alice", 29), Person("Bob", 31)) } fun comparePeople(): Boolean { val p1 = Person("Alice", 29) val p2 = Person("Alice", 29) return p1 == p2 // should be true }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!