e.g. The code below throws a ClassCastException when the second Object is added to the TreeSet. Couldn't TreeSet have been written so that the type parameter can only be a Comparable type? i.e. TreeSet would not compile because Object is not Comparable. That way generics actually do their job - of being typesafe.
import java.util.TreeSet;
public class TreeSetTest {
public static void main(String [] args) {
TreeSet<Object> t = new TreeSet<Object>();
t.add(new Object());
t.add(new Object());
}
}