Java argumenty typu ogólnego [duplikat]

To pytanie ma już odpowiedź tutaj:

Pobierz ogólny typ pliku java.util.List 14 odpowiedzi

Mam metodę, która wymagaList<?> jako argument.

public static String method(List<?> arg){
     // Do something based on type of the list
}

//I call the method as below
List<ClassA> listA = new ArrayList<ClassA>();
List<ClassB> listB = new ArrayList<ClassB>();
method(listA);
method(listB);

Wmethod, skąd mam wiedzieć, czyarg jestList zClassA lub aList zClassB?

questionAnswers(1)

yourAnswerToTheQuestion