相关疑难解决方法(0)

Java Generics,如何在使用类层次结构时避免未经检查的赋值警告?

我想使用一个使用泛型参数的方法,并在类层次结构上返回泛型结果.

编辑:没有 SupressWarnings("未选中")答案允许:-)

这是一个说明我的问题的示例代码:

import java.util.*;

public class GenericQuestion {

    interface Function<F, R> {R apply(F data);}
    static class Fruit {int id; String name; Fruit(int id, String name) {
        this.id = id; this.name = name;}
    }
    static class Apple extends Fruit { 
        Apple(int id, String type) { super(id, type); }
    }
    static class Pear extends Fruit { 
        Pear(int id, String type) { super(id, type); }
    }

    public static void main(String[] args) {

        List<Apple> apples = Arrays.asList(
                new Apple(1,"Green"), new …
Run Code Online (Sandbox Code Playgroud)

java generics compiler-warnings

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

compiler-warnings ×1

generics ×1

java ×1