Hi, I got the code below:
ModuleA.Student student 1 = null; ModuleB.Student student 2 = null; student2 = retrieveStudentFacade().findStudentbyName("John"); student1 = StudentSessionEJBBean.convert(student2,ModuleA.Student.Class);
Now the problem is student1.getId (); return null, but should return a value to me. The following is the converter method, and someone will tell me using this method to reflect objects. It works well, as the error does not occur, just no return value?
UPDATE
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 = instance.getClass().getDeclaredField(targetField.getName()); field.setAccessible(true); targetField.set(target, field.get(instance)); } return target; }
source share