Παράδειγμα: ζευγάρι
class Pair <E1, E2> {
private final E1 element1;
private final E2 element2;
public Pair(final E1 e1, final E2 e2) {
element1 = e1;
element2 = e2;
}
public E1 getFirst() {
return element1;
}
public E2 getSecond() {
return element2;
}
@Override
public String toString() {
return "(" + element1.toString() + ", " + element2.toString() + ")";
}
}
class Sock {}
class Man {}
class Woman {}
class Test {
public static void main(String args[]) {
Pair <Sock, Sock> pairOfSocks;
Pair <Man, Woman> churchMarriedCouple;
Pair <Man, Man> civilPartners;
}
}