java反射 构造函数为什么出现java.lang.NoSuchMethodException
classPerson{privateStringname;privateintage;Person(Stringname,intage){this.name=name;...
class Person
{
private String name;
private int age;
Person(String name, int age)
{
this.name = name;
this.age = age;
}
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;
}
public String toString()
{
return name+age;
}
}
public class Test6 {
public static void main(String[] args) throws Exception
{
Constructor<Person> constructor = Person.class.getConstructor(String.class,int.class);
Person p = constructor.newInstance("zhangsan",26);
}
} 展开
{
private String name;
private int age;
Person(String name, int age)
{
this.name = name;
this.age = age;
}
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;
}
public String toString()
{
return name+age;
}
}
public class Test6 {
public static void main(String[] args) throws Exception
{
Constructor<Person> constructor = Person.class.getConstructor(String.class,int.class);
Person p = constructor.newInstance("zhangsan",26);
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询