Java Generics, how to avoid unchecked assignment warning when using class hierarchy?
问题 I want to use a method using generic parameters and returning generic result on a class hierarchy. edit: no SupressWarnings("unchecked") answer allowed :-) Here is a sample code illustrating my problem: 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