import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import com.pdy.test.User;
//这就是一个实现了深拷贝的反射
public class UseReflectColne2 {
public static Object clone(Object obj) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
System.out.println("come on");
Class> clazz = obj.getClass();
//获取一个无参的构造方法
Constructor> constructor = clazz.getConstructor();
Object result = constructor.newInstance();
//获取所有的field
Field[] fields = clazz.getDeclaredFields();
if(fields != null)
for(int i=0; i<fields.length i string fieldname="fields[i].getName();" firstcharupper="fieldName.substring(0," fieldname.substring getfieldname="get" setfieldname="set" system.out.println object date="clazz.getMethod(getFieldName).invoke(obj);" if date.getclass instanceof number boolean clazz.getmethod return result></fields.length>
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import com.pdy.test.User;
//这就是一个实现了深拷贝的反射
public class UseReflectColne2 {
public static Object clone(Object obj) throws SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
System.out.println("come on");
Class> clazz = obj.getClass();
//获取一个无参的构造方法
Constructor> constructor = clazz.getConstructor();
Object result = constructor.newInstance();
//获取所有的field
Field[] fields = clazz.getDeclaredFields();
if(fields != null)
for(int i=0; i<fields.length i string fieldname="fields[i].getName();" firstcharupper="fieldName.substring(0," fieldname.substring getfieldname="get" setfieldname="set" system.out.println object date="clazz.getMethod(getFieldName).invoke(obj);" if date.getclass instanceof number boolean clazz.getmethod return result></fields.length>