public static <AnyType extends Comparable<? super AnyType>>  AnyType findMax(AnyType[] arr) {
int maxIndex = 0;
for (int i = 1; i < arr.length; i++)
if (arr[i].compareTo(arr[maxIndex]) > 0)
maxIndex = i;
return arr[maxIndex];
}
就第一行public static <AnyType extends Comparable<? super AnyType>>  AnyType findMax(AnyType[] arr)
我怎么看着这么不明白,我知道这个是用泛型的。
我有两个问题:
1. 如果AnyTpye是返回类型的话,那么<AnyType extends Comparable<? super AnyType>>是做什么的?是每个泛型方法必须写的么?
2. <AnyType extends Comparable<? super AnyType>>这个不是很明白是什么意思。如果是<AnyType extends Comparable<AnyType>>这样,我还明白一点。里面的“? super AnyType”是什么意思?