把传过来的Object对象转换成Collection类型的对象。isArray()方法,判定此Class对象是否表示一个数组类。java.lang.reflect.Array 对任意数组进行操作

java.lang.reflect.Array  对任意数组进行操作

private Object items;

private Collection collection;

public void setItems(Object items){

          this.items = items;

           if(items instanceof Collection){

                   collection = (Collection) items;

           }

          if(items instanceof Map){

                     Map map = (Map) items;

                    collection = map.entrySet(); 

          }

                if(items.getClass.isArray()){

                    this.collection = new ArrayList();

                    int length =  Array.getLength(items);

                   for(int i = 0;i < length; i++){

                        Object value = Array.get(items , i);

                         this.collection.add(value);

             }

        }

}

你可能感兴趣的:(java)