Java Method.getReturnType()
Syntax
Method.getReturnType() has the following syntax.
public Class <?> getReturnType()
Example
In the following code shows how to use Method.getReturnType() method.
import java.lang.reflect.Method;
/*from ww w . j a v a 2s .c om*/
public class Main {
public static void main(String[] args) {
String name = "java.util.Date";
try {
Class cl = Class.forName(name);
printMethods(cl);
} catch (ClassNotFoundException e) {
System.out.println("Class not found.");
}
}
public static void printMethods(Class cl) {
Method[] methods = cl.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method m = methods[i];
Class retType = m.getReturnType();
System.out.println(retType.getName());
}
}
}
The code above generates the following result.