2 Replies Latest reply: Jan 8, 2010 3:50 AM by 843798 RSS

    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;