class ArrayAlg
{
public static <T> T min(T[] a) // almost correct
{
if (a == null || a.length == 0) return null;
T smallest = a[0];
for (int i = 1; i < a.length; i++)
if (smallest.compareTo(a[i]) > 0) smallest = a[i];
return smallest;
}
}
//这样就确保类型T一定有compareTo方法
public static <T extends Comparable> T min(T[] a) . .
//也可以继承多个
T extends Comparable & Serializable
3311

被折叠的 条评论
为什么被折叠?



