import java.util.*;
public class zadanie6 {
public static void main(String[] args) {
TreeSet<Integer> i = new TreeSet<Integer>();
TreeSet<Dog> d = new TreeSet<Dog>();
d.add(new Dog(1));
d.add(new Dog(2));
d.add(new Dog(1));
i.add(1);
i.add(2);
i.add(1);
System.out.println(d.size()+" "+i.size());
}
}
class Dog{
int size;
public Dog(int s) {
size = s;
}
}
dlaczego to zwraca podczas runtime Exception
Exception in thread "main" java.lang.ClassCastException: Testy.Dog cannot be cast to java.lang.Comparable
at java.util.TreeMap.compare(Unknown Source)
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at Testy.zadanie6.main(zadanie6.java:13)