How To Instantiate a java.util.ArrayList with Generic Class Using Reflection? I am writing a method that sets java.util.List on target object. A target object and a generic
There's no need to do any reflection for creating your List. Just pass in some additional type information (usually done by passing a class of the correct type).
public static List createListOfType(Class type) {
return new ArrayList();
}
Now you have a list of the required type you can presumably/hopefully set it directly on your targetObject
without any reflection.