@Test public void testHashMethod() { Pair<Integer,String> pair1 = new Pair<>(25, "twenty-five"); Pair<Integer,String> pair2 = new Pair<>(25, "twenty-five"); Pair<Integer,String> pair3 = new Pair<>(null, null); Pair<Integer,String> pair4 = new Pair<>(25, "twentyfive"); Pair<Integer,String> pair5 = new Pair<>(225, "twenty-five"); assertNotSame(pair1, pair2); assertEquals(pair1.hashCode(), pair2.hashCode()); assertNotSame(pair2, pair3); assertNotEquals(pair1.hashCode(), pair4.hashCode()); assertNotEquals(pair1.hashCode(), pair5.hashCode()); }
@Override public int hashCode() { return Objects.hashCode(first) + Objects.hashCode(second); }
Pair { @Override public int hashCode() { return Objects.hashCode(first) + Objects.hashCode(second); } }
Pair { @Override public int hashCode() { return Objects.hashCode(first) + Objects.hashCode(second); } Pair(A f, B s); }
Pair { @Override public int hashCode() { return Objects.hashCode(first) + Objects.hashCode(second); } Pair(A f, B s); @Override int hashCode(); @Override boolean equals(Object o); A getFirst(); B getSecond(); @Override String toString(); String toString(String prefix, String separator, String suffix); Entry<A,B> toMapEntry(); Pair<B,A> swap(); static Pair<K2,V2> fromEntry(Entry<K1,V1> entry); }
Pair { @Override public int hashCode() { return Objects.hashCode(first) + Objects.hashCode(second); } Pair(A f, B s); @Override int hashCode(); @Override boolean equals(Object o); A getFirst(); B getSecond(); @Override String toString(); String toString(String prefix, String separator, String suffix); Entry<A,B> toMapEntry(); Pair<B,A> swap(); static Pair<K2,V2> fromEntry(Entry<K1,V1> entry);  }