2 Replies Latest reply on Jan 8, 2010 9:50 AM by 843798

    Refect an list value into another?

      I know reflection is to get the information of the available class, then below the code I will get the value and set it into another object type. But how about if I got lists :

      List <ClassA> listA ;
      List <ClassB> listB;

      Can I use reflection to reflect listA into listB?
       public static <A, B> B convert(A instance,
                                         Class<B> targetClass) throws Exception {
              B target = (B)targetClass.newInstance();
              for (Field targetField : targetClass.getDeclaredFields()) {
                  Field field =
                  targetField.set(target, field.get(instance));
              return target;