??????????????

import java.lang.reflect.*;
public class ReflectTester {
public Object  copy(Object object) throws Exception{
//???????????
Class classType=object.getClass();
System.out.println("Class:"+classType.getName());
//???????????????????μ????
Object  objectCopy=classType.getConstructor(new Class[]{}).
newInstance(new Object[]{});
//???????????????
Field fields[]=classType.getDeclaredFields();
for(int i=0; i<fields.length;i++){
Field field=fields[i];
String fieldName=field.getName();
String firstLetter=fieldName.substring(0??1).toUpperCase();
//??ú????????? getXXX()??????????
String getMethodName="get"+firstLetter+fieldName.substring(1);
//??ú????????? setXXX()??????????
String setMethodName="set"+firstLetter+fieldName.substring(1);
//??ú????????? getXXX()????
Method getMethod=classType.getMethod(getMethodName??new Class[]{});
//??ú????????? setXXX()????
Method setMethod=classType.getMethod(setMethodName??new Class[]{field.getType()});
//?????????? getXXX()????
Object value=getMethod.invoke(object??new Object[]{});
System.out.println(fieldName+":"+value);
//??????????? setXXX()????
setMethod.invoke(objectCopy??new Object[]{value});
}
return objectCopy;
}
public static void main(String[] args) throws Exception{
Customer customer=new Customer("Tom"??21);
customer.setId(new Long(1));
Customer customerCopy=(Customer)new ReflectTester().copy(customer);
System.out.println("Copy information:"+customerCopy.getName()+
“ "+  customerCopy.getAge());
}
}
???????÷????????÷???
class Customer{
//Customer ??????? JavaBean
private Long id;
private String name;
private int age;
public Customer(){}
public Customer(String name??int age){
this.name=name;
this.age=age;
}
public Long getId(){return id;}
public void setId(Long id){this.id=id;}
public String getName(){return name;}
public void setName(String name){this.name=name;}
public int getAge(){return age;}
public void setAge(int age){this.age=age;}
}
import java.lang.reflect.*;
public class InvokeTester {
public int add(int param1??int param2){  return param1+param2;   }
public String echo(String msg){   return "echo:"+msg; }
public static void main(String[] args) throws Exception{
Class classType=InvokeTester.class;
Object invokeTester=classType.newInstance();
//???? InvokeTester ????? add()????
Method addMethod=classType.getMethod("add"??new Class[]{int.class??int.class});
Object result=addMethod.invoke(invokeTester??
new Object[]{new Integer(100)??new Integer(200)});
System.out.println((Integer)result);
//???? InvokeTester ????? echo()????
Method echoMethod=classType.getMethod("echo"??new Class[]{String.class});
result=echoMethod.invoke(invokeTester??new Object[]{"Hello"});
System.out.println((String)result);
}
}