List<?> Means a list of some type, but we donโt know which type. You can put objects of the desired type on the list, but since you do not know the type, you really cannot put anything on such a list (other than null ).
There is no way around this other than declaring your variable as a List<Integer> .
source share