Skip to content

Instantly share code, notes, and snippets.

@jerolba
Last active June 3, 2019 18:21
Show Gist options
  • Save jerolba/92ec1fa350c86f68d18b0831f92d72d3 to your computer and use it in GitHub Desktop.
Save jerolba/92ec1fa350c86f68d18b0831f92d72d3 to your computer and use it in GitHub Desktop.
HashMap without hashCode
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