Skip to content

Instantly share code, notes, and snippets.

@drulabs
Last active August 8, 2018 19:51
Show Gist options
  • Save drulabs/22c9d006824fae0f8526cdde4c42bd9d to your computer and use it in GitHub Desktop.
Save drulabs/22c9d006824fae0f8526cdde4c42bd9d to your computer and use it in GitHub Desktop.
// Java POJO
public class Person {
private String name;
private int age;
private char gender;
public Person(String name, int age, char gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
public char getGender() { return gender; }
public void setGender(char gender) { this.gender = gender; }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
return age == person.age &&
gender == person.gender &&
Objects.equals(name, person.name);
}
@Override
public int hashCode() {
return Objects.hash(name, age, gender);
}
@Override
public String toString() {
return "Person(" +
"name='" + name + '\'' +
", age=" + age +
", gender=" + gender +
')';
}
}
// Kotlin Data class
data class Person(val name: String, val age: Int, val gender: Char)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment