应该先得到该类的字节码,再由字节码获得该类的Constructor类,再调用Constructor类里的newInstance函数来得到它的构造函数,如你的person类,
下面是他的代码,仅供参考:- Class cls = person.class;
- Constructor constructor = cls.getConstructor(String.class,int.class);
- Person p = (Person)constructor.newInstance(new String("tom",21));
复制代码 |
|