ClassCastException in TreeSet
Hello Java guys,
I have a problem. I keep getting a ClassCastException I don't understand. Let me tell you what happens:
(filling mySet with objects of type A)
Set<A> mySet = new HashSet<A>();
Now I want to order the Set:
BANG! ClassCastException in TreeMap.compare
Set<A> sortedSet = new TreeSet<A>(mySet);
I don't understand it. All the objects in mySet are of type A. Why could he be wanting to cast them anyway?
BTW, the toString() method of type A has been rewritten to return the member String name. If that has something to do with it.
Thanks for reading this,