Created
July 4, 2019 12:07
-
-
Save steven7mwesigwa/3b191cbeafcb3f9d0260aeeaaf828da7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.stevenmwesigwa.equalsandhashcode.demo1; | |
| public class Person { | |
| private String firstname; | |
| private String lastname; | |
| //Getters | |
| //Setters | |
| @Override | |
| public int hashCode() { | |
| int hash = 7; | |
| hash = 29 * hash + Objects.hashCode(this.firstname); | |
| hash = 29 * hash + Objects.hashCode(this.lastname); | |
| return hash; | |
| } | |
| @Override | |
| public boolean equals(Object obj) { | |
| if (this == obj) { | |
| return true; | |
| } | |
| if (obj == null) { | |
| return false; | |
| } | |
| if (getClass() != obj.getClass()) { | |
| return false; | |
| } | |
| final Person other = (Person) obj; | |
| if (!Objects.equals(this.firstname, other.firstname)) { | |
| return false; | |
| } | |
| if (!Objects.equals(this.lastname, other.lastname)) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment