I got a problem ,eg :
Fruit Class
public class Fruit extends Food {
public static void main(String[] args) {
Plate<? super Fruit> plate = new Plate<>(new Food());
plate.setItem(new Apple());
plate.setItem(new Food());
}
static class Apple extends Fruit {
}
}
Food Class
public class Food {
}
Plate Class'
public class Plate<T> {
private T item;
public Plate(T t) {
item = t;
}
public T getItem() {
return item;
}
public void setItem(T item) {
this.item = item;
}
}
I don't understand why
Plate<? super Fruit> plate = new Plate<>(new Food())
not error
but
plate.setItem(new Food())
is error
What is the difference between these two methods?
-that all, thanks!