Which statement is true about the following code?.
class Fruit {}//from w ww .j av a 2 s.co m class Apple extends Fruit {} public class Main { public static void main(String[] args) { List<? extends Apple> lst1 = new ArrayList<Fruit>(); // (1) List<? extends Fruit> lst2 = new ArrayList<Apple>(); // (2) List<? super Apple> lst3 = new ArrayList<Fruit>(); // (3) List<? super Fruit> lst4 = new ArrayList<Apple>(); // (4) List<?> lst5 = lst1; // (5) List<?> lst6 = lst3; // (6) List lst7 = lst6; // (7) List<?> lst8 = lst7; // (8) } }
Select the one correct answer.
(b)
ArrayList<Fruit> is not a subtype of List<? extends Apple>, and ArrayList<Apple> is not a subtype of List<? super Fruit>.
Any generic list can be assigned to a raw list reference.
A raw list and an unbounded wildcard list are assignment compatible.