4 Replies Latest reply: Jun 12, 2010 3:44 AM by 843798 RSS

    Select element from array returned by java.lang.reflect.Method?

    843798
      I would like to invoke a method that returns an array and then just pick the first element.

      So, instead of doing
      int myArr = myObj.getMyArray()[0];{code}
      I would like to use reflection.
      
      {code:java}
      Method method = myObj.getClass().getMethod("getMyArray", new Class[]{});
      int myArr = method.invoke(myObj,  new Class[]{})[0]); // array required, but java.lang.Object found
      {code}How can I get the method to return an element of an array?