I'm using reflection to retrieve an instance field such as this:
private int[] numbers = ....
With the field object, I can check if the field contains an array and if it does, I'd like to loop over the ints in the array. So if the object that contains the above field is called "foo", then I would have something like this:
field.setAccessible(true);
Object value = field.get(foo);
The above value variable will contain my array of ints. How do I treat that object like a regular array and iterate over its values?
Edit: sorry, I missed a crucial point to my story above. I'm doing the above in a generic way so I don't know what primitive the array contains. It could be an int[] or long[] etc. So casting to int[] wouldn't work in the long[] case obviously. oops!