In “Java the Complete Reference” by Herbert Schildt (10th edition), in chapter 14 on Generics there is the following example of a generic method that checks if an object is in an array:
class GenMethDemo {
static <T extends Comparable<T>, V extends T> boolean isIn(T x, V[] y) {
. . .
}
. . .
}
I don’t understand why V extends T is used here.
Why do we allow array’s type to be the subclass of the object that we check for membership? Shouldn’t it be the other way around?