How do I print the method body reflectively?

Posted by kunjaan on Stack Overflow See other posts from Stack Overflow or by kunjaan
Published on 2010-05-31T22:33:19Z Indexed on 2010/05/31 22:43 UTC
Read the original article Hit count: 142

Filed under:
|

Right now I have

private static void getMethods(Class<? extends Object> clazz) {
    Method[] declaredMethods = clazz.getDeclaredMethods();
    for (Method aMethod : declaredMethods) {
      aMethod.setAccessible(true);

      // Print the declaration
      System.out.print(Modifier.toString(aMethod.getModifiers()) + " "
          + aMethod.getReturnType().getSimpleName() + " " + aMethod.getName());

      // Get Parameter Types
      getParameters(aMethod);

      //Empty Body
      System.out.println("{}\n");
    }
  }

Which prints most information reflectively but creates an empty body. How do I add to the reflective nature of Java to print the method body?

© Stack Overflow or respective owner

Related posts about java

Related posts about reflection