4 Replies Latest reply on Apr 14, 2011 1:11 PM by 803691

    How To Instantiate a Generic Class Using Reflection

      How To Instantiate a java.util.ArrayList with Generic Class Using Reflection? I am writing a method that sets java.util.List<T> on target object. Target object and generic type of list is knowing in runtime:

      <code>public static void initializeList(Object targetObject, PropertyDescriptor prop, String genericType) {
      try {
      Class clazz = Class.forName("java.util.ArrayList<"" *++genericType++* ">");
      Object newInstance = clazz.newInstance();
      prop.getWriteMethod().invoke(targetObject, newInstance);
      } catch (Exception e) {