I have two ArrayLists that are equal under the equals() method, but they have different hashcodes. What is going on here?
According to the Java List API: "list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object.hashCode()."
Here is the code:
List<nut> l1= new ArrayList<>(Arrays.asList(new nut((short) 4, (short) 2),
new nut((short) 5, (short) 0), new nut((short) 1, (short) 3)));
List<nut> l2= new ArrayList<>(Arrays.asList(new nut((short) 4, (short) 2),
new nut((short) 5, (short) 0), new nut((short) 1, (short) 3)));
System.out.println(l1.equals(l2));
System.out.println(l1.hashCode());
System.out.println(l2.hashCode());
output: true -2130368428 1856372392