Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get return statements in a java method

Tags:

java

How can I get all possible return values of a method in java?

Example:

Object onEvent() {
 if (condition) {
     return "a";
 }

 if (condition2) {
    return "b";
 }

 if (condition3) {
     return "c";
 } 

}

I need something like this:

String[] returns = Utils.getReturnStatements("object.onEvent()");
returns = ["a", "b", "c"]
like image 808
iberck Avatar asked Dec 20 '22 01:12

iberck


1 Answers

You can only retrieve the method signature, which in this case would be Object as the return type.

To get the any more details you need to either statically analyze the source code or return a type such as an enum.

like image 158
Johan Sjöberg Avatar answered Jan 06 '23 17:01

Johan Sjöberg