You are not the only one struggling with this stuff
Forget your main method and consider only the method:
E is
not being resolved to being Integer. E is any type whatsoever. This is a
generic class which supposed to work for Integer,
String, Apple, Car, Map, anything. Suppose E is chosen to be Apple then you are attempting to return an ArrayList<Integer> instead of an List<Apple>. Suppose E is chosen to be String, then you are attempting to return ArrayList<Integer> instead of an List<String>. Only in the very special case when the E represents Integer would your code be correct. But E has to represent
any type for the class to be generic.
So you can only return an ArrayList<E> to a List<E> for the code to remain generic. (You can also return a raw type of ArrayList but that gives an unchecked warning).