本帖最后由 我手心里的宝 于 2013-4-11 11:39 编辑
- import java.lang.reflect.Constructor;
- public class Demo1 {
- public static void main(String[] args) throws Exception{
-
- Class<Person> clazz = Person.class;
- Constructor<Person> constructor1 = clazz.getConstructor(String.class,int.class);
- Person p1 = constructor1.newInstance("王五",35);
- System.out.println(p1);
- }
- }
- class Person{
- String name = "陈宝峰";
- int age = 24;
- Person(){
-
- }
- Person(String name , int age){
- this.name = "小翠";
- this.age = 25;
- }
- public void setName(){
- this.name = "小宝峰";
- }
- public String getName(){
- return this.name;
- }
- public String toString(){
- return this.name+"::"+this.age;
- }
-
- }
复制代码 哪错了,为什么会报这个异常呢 求解呀 |
|