Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何知道字段是数组?(java.lang.reflect.Field)_Java_Arrays_Reflection_Types_Field - Fatal编程技术网

如何知道字段是数组?(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();
    ...
}