How to get all methods a class is using

Asked

Viewed 188 times

7

I need to find a way to find all the methods a class is using (watch out, it’s not the methods stated in it). EX:

public class Bondia{
    public static void main(String[] args){
    System.out.println("oi");
    System.out.println(new Random().nextInt(10));
    }
}

In this class, for example, I need to list the methods:

  • System.out.println();
  • java.util.Random.nextInt();
  • and preferably the builder as well (new java.util.Random());

Someone knows a way to do that?

  • 7

    This is not something that simple reflection solves. It needs something more complicated, that does bytecode analysis. Maybe some tool such as ASM or javassist.

  • 1

    There is something of Stacktrace that can do this, but I believe the best way would be using javassist.

  • 1

    Use the JDK tool boar. It is disassemble of classes. Ex: no shell type in command line $ javap -c java.lang.Object

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.