While learning Java Generics parametrization I came up to this code:
public interface Comparable<T> {
public int compareTo(T o);
}
public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T elem) {
int count = 0;
for (T e : anArray)
if (e.compareTo(elem) > 0)
++count;
return count;
}
I wanted to test it, so I wrote this:
Integer[] iArray = new Integer[10];
for (int i=0; i<10; i++){
iArray[i] = new Integer(i);
}
int a = countGreaterThan(iArray, Integer.valueOf(5));
but compiler is giving me error message on last line when calling a method countGreaterThan
:
The method countGreaterThan(T[], T) in the type Main is not applicable for the arguments (Integer[], Integer)
Am I missing something obvious?