=====================================================================
import java.lang.reflect.*;
public class LoadParamObject {
- public LoadParamObject() {}
public LoadParamObject(int a, String b) {
- System.out.println("a = " + a + " b = " + b);
public static void main(String args[]) {
- try {
- Class cls = Class.forName("LoadParamObject");
Class partypes[] = new Class[2];
partypes[0] = Integer.TYPE;
partypes[1] = String.class;
Constructor ct = cls.getConstructor(partypes);
Object arglist[] = new Object[2];
arglist[0] = new Integer(37);
arglist[1] = new String("BBB");
Object retobj = ct.newInstance(arglist);
} catch (Throwable e) {
- System.err.println(e);
- Class cls = Class.forName("LoadParamObject");
=====================================================================
The detail explanation please read below:
http://java.sun.com/developer/technicalArticles/ALT/Reflection/
No comments:
Post a Comment