Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions