I am using reflection to get all the get all the methods in a class like this:
Method[] allMethods = c.getDeclaredMethods();
After that I am iterating through the methods
for (Method m: allMethods){
//I want to find out if the return is is a parameterized type or not
m.getReturnType();
}
For example: if I have a method like this one:
public Set<Cat> getCats();
How can I use reflection to find out the return type contain Cat
as the parameterized type?
Have you tried
getGenericReturnType()
?Then (from looking at the Javadocs), it seems that you must cast it to
ParameterizedType
and callgetActualTypeArguments()
on it.So here's some sample code: