Home > Back-end >  The List of Java, the List <?>, with the List <Object> strange questions
The List of Java, the List <?>, with the List <Object> strange questions

Time:05-20

 
//the first case show parameter for the List, can be compiled through, and show in the List. The add didn't prompt error (" 2 s ")
Show (list2);
Show (list3);

Public static void show List (List) {
List. The add (" 2 s ");//there is no error
System. The out. Println (list. Get (0));
}


 
//the second show parameter for List , compile pass
Show (list2);//complains here
Show (list3);//complains here

Public static void show (List The list) {
List. The add (" 2 s ");
System. The out. Println (list. Get (0));
}


 
//the third case show parameter for List<? & gt; , compile, however, show in the list. The add (" 2 s ") error
Show (list2);
Show (list3);

Public static void show (List<? & gt; The list) {
List. The add (" 2 s ");//this error
System. The out. Println (list. Get (0));
}

dear reader, is to explain the above three kinds of situation what's going on
  • Related