Last active
June 10, 2018 04:12
-
-
Save LeoHeo/a1327a68a5eb2a70346ddfb9bdd0a3c5 to your computer and use it in GitHub Desktop.
Revisions
-
LeoHeo revised this gist
Jun 10, 2018 . 2 changed files with 14 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,5 +7,5 @@ public boolean equals(Object o) { return false; } Student student = (Student) o; return Objects.equals(getId(), student.getId()); // Java7+ 부터 사용할 수 있는 `Objects.equals`를 사용해봤다. } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ package io.github.leoheo.equals; public class Main { public static void main(String[] args) { Student leo1 = new Student(1L, "Leo"); Student leo2 = new Student(1L, "Leo"); System.out.println("leo1 hashcode => " + leo1.hashCode()); // 1625635731 System.out.println("leo2 hashcode => " + leo2.hashCode()); // 1580066828 System.out.println("leo1.equals(leo2) => " + leo1.equals(leo2)); // true } } -
LeoHeo created this gist
Jun 10, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ @Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof Student)) { return false; } Student student = (Student) o; return Objects.equals(getId(), student.getId()); }