如何知道字段是数组?(java.lang.reflect.Field)
我从字段中选择了数组:如何知道字段是数组?(java.lang.reflect.Field),java,arrays,reflection,types,field,Java,Arrays,Reflection,Types,Field,我从字段中选择了数组: Field[] fields = instance.getClass().getDeclaredFields(); for (Field field : fields){ if((field.getType() == Integer.class[])||(field.getType() == Object.class[])) { //... } } 如何学习场阵?(如何知道哪个字段是数组(Object[]数组)?),请帮助我。使用: 您可以调用字
Field[] fields = instance.getClass().getDeclaredFields();
for (Field field : fields){
if((field.getType() == Integer.class[])||(field.getType() == Object.class[]))
{
//...
}
}
如何学习场阵?(如何知道哪个字段是数组(Object[]数组)?),请帮助我。使用:
您可以调用字段类型的类
对象。要获取元素的类型,请调用方法
if (field.getType().isArray()) {
...
}
if((field.getType().isArray()) {
Class componentType = field.getType().getComponentType();
...
}