Created
February 28, 2018 14:30
-
-
Save albanoj2/8601c974d9ed357cafea914a4b290538 to your computer and use it in GitHub Desktop.
This file contains 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
public class Foo { | |
@Override | |
public boolean equals(Object obj) { | |
if (this == obj) { | |
return true; | |
} | |
else if (obj == null || obj.getClass() != getClass()) { | |
return false; | |
} | |
else { | |
Foo foo = (Foo) obj; | |
return Objects.equals(foo.firstName, firstName); | |
} | |
} | |
} | |
Foo foo = new Foo("John"); | |
Foo fooIdentical = new Foo("John"); | |
Bar bar = new Bar("John"); | |
Set < Foo > foos = new HashSet < > (); | |
foos.add(foo); | |
foos.add(fooIdentical); | |
System.out.println(foos); // [Foo@23514a] | |
foos.add(bar); | |
System.out.println(foos); // [Foo@23514a, Bar@23514a] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment