Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created October 24, 2024 09:44
Show Gist options
  • Select an option

  • Save karthiks/9290d9d94e76506663c124fcf5673162 to your computer and use it in GitHub Desktop.

Select an option

Save karthiks/9290d9d94e76506663c124fcf5673162 to your computer and use it in GitHub Desktop.

Revisions

  1. karthiks created this gist Oct 24, 2024.
    41 changes: 41 additions & 0 deletions PersonAddress.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    public class Person {
    private Long id;
    private String name;
    @Override
    public int hashCode() {
    return Objects.hash(id, name);
    }
    @Override
    public boolean equals(Object obj) {
    if (this == obj)
    return true;
    if (obj == null)
    return false;
    if (getClass() != obj.getClass())
    return false;
    Person other = (Person) obj;
    return Objects.equals(id, other.id) && Objects.equals(name, other.name);
    }
    }

    class Address {
    private String road;
    private String city;
    private String pincode;
    @Override
    public int hashCode() {
    return Objects.hash(city, pincode, road);
    }
    @Override
    public boolean equals(Object obj) {
    if (this == obj)
    return true;
    if (obj == null)
    return false;
    if (getClass() != obj.getClass())
    return false;
    Address other = (Address) obj;
    return Objects.equals(city, other.city) && Objects.equals(pincode, other.pincode)
    && Objects.equals(road, other.road);
    }
    }