I want to create a generic method that accepts only an arraylist of integers. But the method is also accepting a raw type. How can I restrict it to accept only an arraylist of integers?
package generics;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class GenericBox<T> {
public static void main(String[] args) {
ArrayList l1 = new ArrayList();
l1.add(1);
l1.add("subbu");
printListValues(l1);
ArrayList<Integer> l2 = new ArrayList<>();
l2.add(1);
l2.add(2);
printListValues(l2);
}
public static <T extends ArrayList<Integer>> void printListValues(T t){
System.out.println(t);
}
}
Thank you, Subbu.