Skip to content

Instantly share code, notes, and snippets.

@emanguy
Created April 10, 2021 02:55
Show Gist options
  • Select an option

  • Save emanguy/977d7b2941c1a0b77317d9b6cfd8763e to your computer and use it in GitHub Desktop.

Select an option

Save emanguy/977d7b2941c1a0b77317d9b6cfd8763e to your computer and use it in GitHub Desktop.
Java vs. Kotlin
public class Person {
private String name;
private String occupation;
private int age;
public Person(String name, String occupation, int age) {
this.name = name;
this.occupation = occupation;
this.age = age;
}
public void setName(String newName) {
this.name = newName;
}
public String getName() {
return this.name;
}
public void setOccupation(String newOccupation) {
this.occupation = newOccupation;
}
public String getOccupation() {
return this.occupation;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return this.age;
}
public String toString() {
return "Person(name="+this.name+", occupation="+this.occupation+", age="+this.age+")";
}
public int hashCode() {
// I know, this is a really bad implementation but bear with me
return this.name.hashCode() + this.occupation.hashCode() + this.age;
}
public bool equals(Object other) {
if (!(other instanceof Person)) {
return false;
}
Person otherPersion = (Person) other;
return this.name.equals(otherPerson.getName()) && this.occupation.equals(otherPerson.getOccupation()) && this.age == other.getAge();
}
}
data class Person(var name: String, var occupation: String, var age: Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment