Which code fragments print 1?
A.
String arr [] = {“1”, “2”, “3”};
List <? extendsString > arrList = new LinkedList <> (Arrays.asList (arr));
System.out.println (arrList.get (0));
B.
String arr [] = {“1”, “2”, “3”};
List <Integer> arrList = new LinkedList <> (Arrays.asList (arr));
System.out.println (arrList.get (0));
C.
String arr [] = {“1”, “2”, “3”};
List <?> arrList = new LinkedList <> (Arrays.asList (arr));
System.out.println (arrList.get (0));
D.
String arr [] = {“1″,”2″,”3”};
List <?> arrList = new LinkedList <?>(Arrays.asList (arr));
System.out.println (arrList.get (0));
E.
String arr [] = {“1″,”2″,”3”};
List <Integer> extendsString > arrList =new LinkedList <Integer> (Arrays.asList (arr));
System.out.println (arrList.get (0));
Explanation:
Note:You can replace the type arguments required to invoke the constructor of a generic class
with an empty set of type parameters (<>) as long as the compiler can infer the type arguments
from the context. This pair of angle brackets is informally called the diamond.
Ans: A,D