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"]
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With