java - Using reflection to retrieve an array of primitives of an unknown type -


I am using reflection to retrieve an example field like this:

  Private int [] numbers = .... ....  

With field objects, I can check that the field has an array and if this happens, then I want to loop on the array in the array. So if the object in the above area is called "Fu", then I have something like this:

  field.setAccessible (true); Object value = field. Get (foo);  

The above value variables will include an array of my ints. How do I do that object like a regular array and iterate over its values?

Edit: Sorry, I remember an important point for the above story, I have been doing the above method in a normal way so I do not know what the array Primitive it can be an int [] or long [] etc. Therefore casting [int] [] clearly will not work [long for long]. Oh, is that so!

You can use class java.lang.reflect.Array To access the length of an array and the individual elements, the get method should work normally, perhaps wrapping the oldest in its wrapper items.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -