4 Replies Latest reply on Jun 12, 2010 8:44 AM by 843798

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

      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.
      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?