比如有一个类
class A{
String aaa;
String bbb;
Integer ccc;
boolean ddd;}怎么才能够得到定义在A这个类里的String 类型的字段名和Integer类型的字段名

解决方案 »

  1.   

    http://orangewhy.javaeye.com/blog/56011
      

  2.   

    通过Field类的getType方法判断属性的类型。
      

  3.   

    import java.lang.reflect.*;
    class A{
    String aaa;
    String bbb;
    Integer ccc;
    boolean ddd;
    }
    public class TestField{
    public static void main(String args[])throws Exception{
    Field fields[] = A.class.getDeclaredFields();
    for(int i=0;i<fields.length;i++){
    fields[i].setAccessible(true);
    Type type = fields[i].getType() ;
    if(type == java.lang.String.class){
    System.out.println(fields[i].getName()+" is a string!" );
    }else if(type == java.lang.Integer.class){
    System.out.println(fields[i].getName()+" is a Integer!" );
    }
    }
    }
    }
      

  4.   

    为什么不能用GET  SET方法呢?