当我尝试运行以下代码时,编译器生成了以下异常信息:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: JTOGenerics.ArrayCode.countGreaterThan at JTOGenerics.ArrayCode.main(ArrayCode.java:17) Java Result: 1
在代码的下面一行有一条红线: int av = ArrayCode.countGreaterThan(marks, 10);
作为一名Java新手,由于我的知识有限,我试图定位错误,但未能成功。请问有谁能帮帮我吗?非常感谢!
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: JTOGenerics.ArrayCode.countGreaterThan at JTOGenerics.ArrayCode.main(ArrayCode.java:17) Java Result: 1
在代码的下面一行有一条红线: int av = ArrayCode.countGreaterThan(marks, 10);
作为一名Java新手,由于我的知识有限,我试图定位错误,但未能成功。请问有谁能帮帮我吗?非常感谢!
public class ArrayCode<T> implements Comparable<T> {
public static void main(String[] args) {
Integer[] marks = new Integer[] {12, 0, 15, 18, 4};
int av = ArrayCode.countGreaterThan(marks, 10);
System.out.println("the number of Marks that are greater than 10 is: " + av);
}
public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
int count = 0;
for (T e : anArray) {
if (((Comparable<T>)e).compareTo(elem) > 0) {
++count;
}
}
return count;
}
@Override
public int compareTo(T o) {
if (this.equals(o)) {
return 1;
} else {
return 0;
}
}
public interface Comparable<T> {
public int compareTo(T o);
}
}