@Test public void testHashCode() { Pair<Integer, String> pair1 = new Pair<Integer, String>(1, "one"); Pair<Integer, String> pair2 = new Pair<Integer, String>(1, "one"); assertEquals(pair1.hashCode(), pair2.hashCode()); pair2 = new Pair<Integer, String>(1, "two"); assertFalse(pair1.hashCode() == pair2.hashCode()); pair1 = new Pair<Integer, String>(null, "one"); pair2 = new Pair<Integer, String>(null, "one"); assertEquals(pair1.hashCode(), pair2.hashCode()); pair1 = new Pair<Integer, String>(1, null); pair2 = new Pair<Integer, String>(1, null); assertEquals(pair1.hashCode(), pair2.hashCode()); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((first == null) ? 0 : first.hashCode()); result = prime * result + ((second == null) ? 0 : second.hashCode()); return result; }
Pair { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((first == null) ? 0 : first.hashCode()); result = prime * result + ((second == null) ? 0 : second.hashCode()); return result; } }
Pair { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((first == null) ? 0 : first.hashCode()); result = prime * result + ((second == null) ? 0 : second.hashCode()); return result; } Pair(F first, S second); }
Pair { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((first == null) ? 0 : first.hashCode()); result = prime * result + ((second == null) ? 0 : second.hashCode()); return result; } Pair(F first, S second); F getFirst(); S getSecond(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
Pair { @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((first == null) ? 0 : first.hashCode()); result = prime * result + ((second == null) ? 0 : second.hashCode()); return result; } Pair(F first, S second); F getFirst(); S getSecond(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }