If we want to force the method to allow particuler type list or it’s super classes type list as parameter we have to use super keyword. See , below example.
public int size(List<? super X> arrayList) {
—-
}
1) If X is a class then above method is applicable for ArrayList of X type or its super classes .
2) If X is a interface then above method is applicable for ArrayList of X type or super classes of X implementation types.
3) With in the method we can add X type elements and ‘null’ only . See the below example.
import java.util.ArrayList; import java.util.List; public class Sample { public int size(List<? super String> arrayList) { arrayList.add("raj"); return arrayList.size(); } public static void main(String as[]) { List<String> names = new ArrayList<String>(); List<Integer> age = new ArrayList<Integer>(); names.add("sree"); names.add("krish"); System.out.println(new Sample().size(names)); } }