本帖最后由 Rockray 于 2014-4-1 13:39 编辑
请看下面代码:
- import java.lang.reflect.*;
- public class Test5{
- public static void main(String[] args) throws Exception{
- Constructor cons = Person.class.getConstructor();
- }
- }
- class Person {
- private String name;
- private int age;
-
- Person(){
- }
-
- 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;
- }
- }
复制代码
编译通过,运行时会抛出 NoSuchMethodException异常
请问怎么解决啊?
|
|