1

Hello I am curious about possibility of finding all methods that are used in a Java class. So far I tried stuff like java.lang.reflect.Method including:

className.class.getMethods(); - it's not giving me expected result.

Expected Result:

I want to get all methods that are used in class like : Java.lang.Object.equals()

shahaf
  • 4,750
  • 2
  • 29
  • 32
Enrique
  • 31
  • 4
  • 2
    That's not possible. You'd need to parse the source files to determine whether a method is used or not, even then you're not guaranteed to catch all calls (for example calling methods with reflection). – Kayaman Oct 08 '19 at 09:00
  • I think this may answer your question: [Answered in a similar question](https://stackoverflow.com/a/31204747/5436073) – Thoma Oct 08 '19 at 10:18
  • @Thoma: the answer you linked to answers a very different question, namely which methods *exist* in a given class. – Joachim Sauer Oct 08 '19 at 10:55
  • Ah, sorry, my bad. – Thoma Oct 08 '19 at 10:58
  • @Kayaman: You don't need the source, the bytecode of the class contains the method calls (again with the caveat of reflection, though). There should be some static analysis tool that can come up with this information. – Thilo Oct 08 '19 at 11:15
  • @Thilo yea, didn't mean the literal source code. Rather that it's impossible to do with runtime reflection and it's not fool-proof even if doing source/bytecode analysis. – Kayaman Oct 08 '19 at 11:17

0 Answers0