I wish to a check if a method exists in an interface based on its signatures.
The signature that the method should have is:
Collection<Foo> methodName(Spam arg0, Eggs arg1, ...)
I can find the methods via Class.getMethods()
then find the name, parameters and return type respectively with method.getName()
, method.getParameterTypes()
and method.getReturnType()
.
But what do I compare the return type to in order to ensure that only methods that return Collection<Foo>
are chosen, and not other collections?
method.getReturnType().equals(Collection.class)
Since the above will be true for all methods that return a collection, not just for those that return a Foo
Collection.