Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
Hallo, können jemand mir weiter helfen, wie ich richtig machen kann, dass ein solche Paar der Klasse Pair<? ?> gleich mit anderen Paar sein, wenn linker und rechte Teil jewils geich sind.
public class PairTest {
@Test
public void equals() {
Pair<Long, String> first = new Pair<Long, String>(1L, "eins");
Pair<Long, String> second = new Pair<Long, String>(1L, "eins");
assertTrue(first.equals(second));
}
@Test
public void inverse() {
Pair<Long, String> first = new Pair<Long, String>(1L, "eins");
Pair<String, Long> second = new Pair<String, Long>("eins", 1L);
assertTrue(first.equals(second));
}
}
Java:public class Pair<L,R> { private L left; private R right; public Pair( L left, R right){ this.left = left; this.right = right; } public L getLeft(){ return left; } public R getright(){ return right; } public boolean equals(Object obj){ if (this == obj){ return true; } if (obj == null ||this.getClass() != obj.getClass()){ return false; } if (!(obj instanceof Pair)){ return false; } Pair<?,?> other = (Pair<?,?>) obj; //unchecked cast if (!left.equals(other.left) && !left.equals(other.right)) { return false; } if (!right.equals(other.right) && !right.equals(other.left)) { return false; } return true; } }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((left == null) ? 0 : left.hashCode());
result = prime * result + ((right == null) ? 0 : right.hashCode());
return result;
}