- import java.lang.reflect.Field;
- public class Demo {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Class clazz = new Student().getClass();
- Field[] fld = clazz.getFields();
-
- for(Field f : fld){
- System.out.println(f.toGenericString());
- }
- // System.out.println(fld.length);
-
- //clazz.getField(name);
-
- }
- }
- class Person{
- public String name = "name";
- public int age = 18;
- }
- class Student extends Person{
- public int studentId = 0;
- }
复制代码 输出结果:
public int test.Student.studentId
public java.lang.String test.Person.name
public int test.Person.age
|