Παράδειγμα: ζευγάρι

class Pair <E1, E2> {
    private E1 element1;
    private E2 element2;
    public Pair(E1 e1, E2 e2) {
        element1 = e1;
        element2 = e2;
    }
    public E1 getFirst() {
        return element1;
    }
    public E2 getSecond() {
        return element2;
    }
    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;
    }
}