Why this is wrong:
Class extends Number> type = Integer.class;
ArrayList = new ArrayList<>();
?
I
Feel the difference between java Class (which actually generic too) object and class name.
You should use class name specifying generic type.
ArrayList = new ArrayList<>();
// ArrayList = new ArrayList<>(); <- WRONG
Use this approach if you'll know type only in runtime:
public void createAList(Class type) {
ArrayList toReturn = new ArrayList<>();
return toReturn;
}