本帖最后由 Kelvinhu 于 2014-4-15 10:52 编辑
Constructor[] cons = Student.class.getConstructors(); //想要返回Student类中所有的构造方法,这样做为什么返回不了。。求解。
贴上代码。。。
- package Testpackage;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.Method;
- import java.util.Date;
- public class Test {
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- Student a = new Student();
- Class cls = a.getClass();
- System.out.println(cls);
- Method gstudy = cls.getMethod("study", null);
- System.out.println(gstudy);
- Constructor[] cons = Student.class.getConstructors(); //想要返回Student类中所有的构造方法,这样做为什么返回不了。。求解。
- for (Constructor co : cons) {
- System.out.println(co);
- }
- }
- }
- class Student {
- private int grade;
- private static int teststatic;
- Student() {
- this.grade = 0;
- }
- Student(int i) {
- this.grade = i;
- }
- public void study() {
- System.out.print("like study");
- grade = 100;
- teststatic = 0;
- }
- public void sleep() {
- System.out.print("like sleep");
- }
- static void play() {
- System.out.print("like play");
- teststatic = 0;
- }
- }
复制代码 |