Android Object Clone clone(Class clazz, Object source, Object dest)

Here you can find the source of clone(Class clazz, Object source, Object dest)

Description

clone

License

Open Source License

Declaration

private static void clone(Class<?> clazz, Object source, Object dest) 

Method Source Code

//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);
        }
    }
}

Related

  1. clone(final Object obj)
  2. clone(final Object obj)
  3. clone(Object source, Object dest)