Date: 2010-03-01 12:02 pm (UTC)
Чуток обновлённая версия:
interface Comparable<C> {
    boolean greater(C other);
}
interface Comparator<C> {
    boolean isGreater(C first, C second);
}
class DefComp<C extends Comparable<C>> implements Comparator<C> {
    public boolean isGreater(C first, C second) {
	return first.greater(second);
    }
}
interface Set<C> {
    void add(C item);
}
class TreeSet<C> implements Set<C> {
    Comparator<C> comparator;
    TreeSet(Comparator<C> _comparator) {
	comparator = _comparator;
    }
    public void add(C item) {
	if (comparator.isGreater(item, item)){
	    return;
	} else {
	    return;
	}
    }
}
class TreeSetFactory{
    public static <C extends Comparable<C>> TreeSet<C> getTreeSet() {
	return new TreeSet<C>(new DefComp<C>());
    }
}
class TestComp implements Comparable<TestComp> {
    public boolean greater(TestComp other) {
	return true;
    }
}
class Test {
    void test() {
	TreeSet<TestComp> treeSet = TreeSetFactory.<TestComp>getTreeSet();
	return;
    }
}
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting