我目前正在学习泛型我在这里有这个泛型类
package generics.lesson;
public class Pair<T> {
private T first;
private T second;
public Pair(){ first = null; second = null; }
public Pair(T first, T second){ this.first = first ; this.second = second;}
public T getFirst() { return first; }
public T getSecond() { return second; }
public void setFirst(T first) { this.first = first; }
public void setSecond(T second) { this.second = second; }
}
到目前为止我明白这一点,但后来我遇到了这个
public static Pair<String> minmax(String[] a)
{
if(a.length == 0 || a == null) return null;
String min = a[0];
String max = a[0];
for(int i = 1 ; i < a.length ; i++)
{
if(min.compareTo(a[i])>0) min = a[i];
if(max.compareTo(a[i])<0) max = a[i];
}
return new Pair<String>(min,max);
}
让我困惑的是
public static Pair<String> minmax(String[] a)
问题
这怎么可能?泛型类可以是方法返回类型吗?