Here you can find the source of clone(Class> clazz, Object source, Object dest)
private static void clone(Class<?> clazz, Object source, Object dest)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Field; import java.lang.reflect.Modifier; public class Main { public static void clone(Object source, Object dest) { clone(source.getClass(), source, dest); }/*from w w w .j a va 2 s . c o m*/ private static void clone(Class<?> clazz, Object source, Object dest) { Field[] declaredFields = clazz.getDeclaredFields(); try { for (Field field : declaredFields) { field.setAccessible(true); if (Modifier.isFinal(field.getModifiers())) { continue; } field.set(dest, field.get(source)); } } catch (Exception e) { e.printStackTrace(); } if (clazz.getSuperclass() != null && clazz.getSuperclass() != Object.class) { clone(clazz.getSuperclass(), source, dest); } } }