1

In my spring application i need to identify the methods in a java file which is saved in a temporary location(Files not in the current project)

eg: C:\Users\Guest\Desktop\File.java i need to get the all the methods in this file

is there a way to change the below code or any other methods

ClassName t = new ClassName();

        Class tClass = t.getClass();
        Method[] methods = tClass.getMethods();
        for (int i = 0; i < methods.length; i++) {
            System.out.println("public method: " + methods[i]);
        }
4
  • 3
    Either compile the .java file, and then you can use the reflection approach, or if all you really need is the method names, you should be able to derive a regular expression to parse the file. Commented Mar 23, 2019 at 22:12
  • As @KevinO says use the reflection !! take a look at this article link Commented Mar 23, 2019 at 22:39
  • Or use a language recognition tool such as ANTLR 4. Commented Mar 24, 2019 at 0:03
  • Hi @KevinO I need all the parameters return types and exceptions too Commented Mar 24, 2019 at 8:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.