When I tried to run the code below, the compiler generates
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
There is a red line beneath the line of code: int av = ArrayCode.countGreaterThan(marks, 10);
I'm new to Java and due to my limited knowledge, I tried and failed to locate the error, could someone please help me out? Many thanks in advance!!
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);
}
}