Boa tarde pessoal…
Alguém pode por favor me ajudar a entender por que o código abaixo lança uma
Exception in thread "main" java.lang.ClassCastException: test cannot be cast to java.lang.Comparable
at java.util.TreeMap.put(Unknown Source)
at java.util.TreeSet.add(Unknown Source)
at test.main(test.java:10)
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]
import java.util.*;
public class test implements Comparator<test> {
int testNumber;
public static void main(String[] args) {
Set<test> s1 = new TreeSet<test>();
s1.add(new test());
s1.add(new test());
}
@Override
public int compare(test t1, test t2) {
return t1.testNumber-t2.testNumber;
}
}
Obrigado 