Field[] fs = clazz.getFields();
for (Field f : fs) {
Class<?> classType = f.getType();

if (!classType.isPrimitive() && classType != String.class && ) {

}
}
上面已对:String.class、int.class(等8种)判断了,但如何判断Integer.class等8种呢?

解决方案 »

  1.   

    入口类型                                标志值CONSTANT_Class                           7CONSTANT_Fieldref                        9CONSTANT_Methodref                       10CONSTANT_InterfaceMethodref              11CONSTANT_String                           8CONSTANT_Integer                          3CONSTANT_Float                            4CONSTANT_Long                             5CONSTANT_Double                           6CONSTANT_NameAndType                      12CONSTANT_Utf8                              1
      

  2.   

    Integer.class跟String.class一样判断
      

  3.   


    这种那要写8个,我是想找到一种如:classType.isPrimitive()一次可判断8、9个的目前是用数组把这个8个存起来,循环判断,不知有没有更好的方法
      

  4.   

    boolean java.lang.Class.isPrimitive()
    Determines if the specified Class object represents a primitive type. There are nine predefined Class objects to represent the eight primitive types and void.void也会为true
    循环估计最优了
      

  5.   

    做个方法,往里传值是object类型,然后用传到的值跟方法内部设定已知的类型循环判断,并返回
      

  6.   


    void也为true也无所谓,因为得到的是Field[],无论无何,它里面的值是不可能为void.class的