相关疑难解决方法(0)

问题<T延伸可比较<?超级T >>

我有一个三类:1.class 在a Algorithmmax()找到最大值Collection:

public class Algorithm {

    public static <T extends Comparable<T>> T max(Collection<? extends T> coll) {
        T max = coll.iterator().next();

        for (T elm : coll) {
            if (max.compareTo(elm) < 0)
                max = elm;
        }

        return max;
    }
}
Run Code Online (Sandbox Code Playgroud)

2.Class Fruit:

public class Fruit implements Comparable<Fruit> {
    private String name;
    private int size;

    public Fruit(String name, int size) {
        this.name = name;
        this.size = size;
    }

    public int compareTo(Fruit that) {
        if (size …
Run Code Online (Sandbox Code Playgroud)

java generics collections

4
推荐指数
1
解决办法
4054
查看次数

标签 统计

collections ×1

generics ×1

java ×1