Announcement Announcement Module
Collapse
No announcement yet.
Java Reflection:Extracing individual item from an array of unknown type/dimension Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Java Reflection:Extracing individual item from an array of unknown type/dimension

    I am trying to use Java Reflection APIs for extracting all member items from an array of unknown type and unknown dimension??


    Any ideas?

  • #2
    I would imagine doing something like (pseudocode)

    Code:
    dump(Object obj) {
      if ( obj == null ) {
        ...handle null...
      } else if ( obj.getClass().isArray() ) {
        for ( int i =0; i < Array.getLength(obj); i++ ) {
          dump(Array.get(obj,i));
        }
      } else {
        ...handle non-array object...
      }
    }
    Of course, in real life you may prefer non-recursive approach, put Array.getLength out of loop, etc.

    Comment

    Working...
    X