Are there any open-source tools available which support searching for Java methods by the set of parameter types and return type?
As an example, say I’m looking for a method to generate a hash code for an array of ints. I search for a method which takes an int[] parameter and returns an int:
int[] -> int
yielding
java.util.Arrays#hashCode(int[])
...
Or I may want to find a method which takes a String, and character to replace, and the character to replace it with. So I search for a matching method:
String, char, char -> String
yielding
java.lang.String#replace(char, char)
...
Ideally I’d like a Java equivalent to Haskell’s Hoogle, which supports searching for functions by type signature.
I’d expect the tool to:
- ignore the order of parameters
- include methods which accept ‘wider’ types as parameters (e.g. superclasses)
- include methods which return ‘narrower’ types as return values (e.g. subclasses)
- treat the ‘self’ value as a parameter to instance methods (e.g. ‘String -> int’ would include String#hashCode)
I’m aware that many IDEs support searching for methods which take or return a given type, but haven’t yet seen a tool to narrow the search by the combination of parameter types and return type.
Solution comments:
Integer.class=Integer.TYPE)findMethodmethodThis is the output of the program:
The code: