Java tutorial
//package com.java2s; import java.lang.reflect.Field; public class Main { public static void copyBean(Object from, Object to) { Class<?> beanClass = from.getClass(); Field[] fields = beanClass.getFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; field.setAccessible(true); try { Object value = field.get(from); field.set(to, value); } catch (Exception e) { } } } }