Last active
June 3, 2019 18:21
-
-
Save jerolba/92ec1fa350c86f68d18b0831f92d72d3 to your computer and use it in GitHub Desktop.
HashMap without hashCode
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 Person { | |
private Integer id; | |
private String name; | |
public Person(Integer id, String name) { | |
this.id = id; | |
this.name = name; | |
} | |
} | |
public static void main(String[] args) { | |
Map<Person, Integer> map = new HashMap<>(); | |
map.put(new Person(1, "Alberto"), 35); | |
map.put(new Person(2, "Ana"), 28); | |
//more operations and in a place away from previous code... | |
map.put(new Person(1, "Alberto"), 36); | |
System.out.println(map.size()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment