Answer the question
In order to leave comments, you need to log in
How can this method be used on non-primitive objects?
Method:
public static <T extends Comparable<T>> int F(T[] anArray, T elem) {
int count = 0;
for (T e : anArray)
if (e.compareTo(elem) > 0)
++count;
return count;
}
Answer the question
In order to leave comments, you need to log in
I will surprise you, but this method is only possible on non-primitive objects of use. Java primitives cannot parametrize generics.
The class must implement Comparable, and then objects of this class can be passed to this method.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question