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

前端 未结 6 1807
伪装坚强ぢ
伪装坚强ぢ 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:36

    One can access each element of an array separately using the following code:

    Object o=...;
    if ( o.getClass().isArray() ) {
        for(int i=0; i

    Notice that it is unnecessary to know what kind of underlying array it is, as this will work for any array.

提交回复
热议问题