0

The following snippet is part of a huge Java project that I'm working on:

        Map<String, String> method_types = new HashMap<String, String>();
        Method[] methods = ClassLoader.getSystemClassLoader().loadClass("className").getDeclaredMethods();

        for (Method method : methods) {
            String type = Modifier.toString(method.getModifiers());
            method_types.put(method.getName(), type);
            System.out.println("-> " + method.getName() + " -- " + Modifier.toString(method.getModifiers()));
        }

This will print the following:

-> zoo -- private 
-> zoo -- public 
-> boo -- public 
-> thro -- private 
-> foo -- protected 

What I want is to print the methods along with their parameters such as:

ArtClassPrivateMethod.zoo(I)V
ArtClassPrivateMethod.boo(I)Z
ArtClassPrivateMethod.zoo(II)V
ArtClassPrivateMethod.thro()V
ArtClassPrivateMethod.<init>(Ljava/lang/String;)V

Note that the method zoo(II)V is the private one.

Is that possible to be printed?

Adam Amin
  • 1,406
  • 2
  • 11
  • 23
  • 1
    It's not completely clear what do you what's requirement. It you need to print only parameter types there's `Method.getParameterTypes()` method. If you would print also parameter names here's detailed topic https://stackoverflow.com/a/20594685/2553521 – edwgiz Jan 16 '20 at 18:48
  • Did you try using the command line tool `javap`? – Yserbius Jan 16 '20 at 18:54

0 Answers0