Java Reflection Java Java API
java.lang.reflect.Method
public Class<?> getReturnType()
Returns a Class object that represents the formal return type of the method represented by this Method object.
Class
Method
package com.logicbig.example.method;import java.lang.reflect.Method;import java.math.BigDecimal;public class GetReturnTypeExample { private static BigDecimal getNumber() {return null;} public static void main(String... args) throws NoSuchMethodException { Method m = GetReturnTypeExample.class.getDeclaredMethod("getNumber"); Class<?> returnType = m.getReturnType(); System.out.println(returnType.getTypeName()); }}
java.math.BigDecimal
package com.logicbig.example.method;import java.lang.reflect.Method;public class GetReturnTypeExample2 { private static void process() {} public static void main(String... args) throws NoSuchMethodException { Method m = GetReturnTypeExample2.class.getDeclaredMethod("process"); Class<?> returnType = m.getReturnType(); System.out.println(returnType.getTypeName()); }}
void