views:

46

answers:

1

I have

Class<? extends Object> class1 = obj.getClass();
    Field[] fields = class1.getDeclaredFields();
    for (Field aField : fields) {
      aField.setAccessible(true);
       if (aField.getType().isArray()) {
          for (?? vals : aField) {
            System.out.println(vals);
          }
        }
      }
+3  A: 

You'd use something like this:

if (aField.getType().isArray()) {
  Object array = aField.get(obj);
  int length = Array.getLength(array);
  for (int i = 0; i < length; i++) {
    System.out.println(Array.get(array, i));
  }
}

In other words, you first fetch the value from the field using Field.get, then use the java.lang.reflect.Array helper class to access the length and the individual elements.

Jon Skeet