Struts调用的BeanUtils反射的基本原理

import java.lang.reflect.Method;  
import java.sql.Date;  
public class Methoder {  
    /** 
     * @param args 
     */  
    public static void main(String[] args) throws Exception {  
        Class<?> clazz = Class.forName("InvokedClass");  
        Object o = clazz.newInstance();  
          
        Class<?> types[] = new Class[3];  
        types[0] = Class.forName("java.lang.String");  
        types[1] = Class.forName("java.sql.Date");  
        types[2] = int.class;  
        Method m = clazz.getDeclaredMethod("sayHello", types);  
        m.invoke(o, "libram", Date.valueOf("1988-8-8"), 19);  
          
        System.out.println(o.toString());  
    }  
}  
class InvokedClass {  
    private String name;  
    private Date birth;  
    private int age;  
    public void sayHello(String name, Date birth, int age) {  
        this.name = name;  
        this.birth = birth;  
        this.age = age;  
    }  
    public String toString() {  
        return "name = " + name + "\tbirth = " + birth.toString() + "\tage = "  
                + age;  
    }  
}  

One thought on “Struts调用的BeanUtils反射的基本原理”

Comments are closed.