How to see if an object is an array without using reflection?

前端 未结 6 1810
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 04:08

How can I see in Java if an Object is an array without using reflection? And how can I iterate through all items without using reflection?

I use Google GWT so I am n

6条回答
  •  死守一世寂寞
    2020-12-01 04:47

    You can create a utility class to check if the class represents any Collection, Map or Array

      public static boolean isCollection(Class rawPropertyType) {
            return Collection.class.isAssignableFrom(rawPropertyType) || 
                   Map.class.isAssignableFrom(rawPropertyType) || 
                   rawPropertyType.isArray();
     }
    

提交回复
热议问题