首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

哪位高手能告诉小弟我这个泛型方法是什么意思

2012-10-20 
谁能告诉我这个泛型方法是什么意思?Java codepublic static AnyType extends Comparable? super AnyType

谁能告诉我这个泛型方法是什么意思?

Java code
    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”是什么意思?

[解决办法]
探讨
1.<AnyType extends Comparable<? super AnyType>>表示对AnyType的一个限定。必须实现Comparable
2.“? super AnyType”表示 接受AnyType或AnyType的父类。

热点排行