Why does TreeSet throw a ClassCastException?
Either Employee has to implement Comparable, or you need to provide a comparator when creating the TreeSet. This is spelled out in the documentation for SortedSet: All elements inserted into a sorted set must implement the Comparable interface (or be accepted by the specified comparator). Furthermore, all such elements must be mutually comparable: e1.compareTo(e2) (or … Read more