Here you can find the source of getMethodReturnType(Class> clazz, String name)
Parameter | Description |
---|---|
clazz | the Class object whose declared methods to be checked for the wanted method name. |
name | the method name as String to be compared with Method#getName() |
public static Class<?> getMethodReturnType(Class<?> clazz, String name)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { /**/*from ww w . ja v a 2 s. c o m*/ * Returns a {@code Class} object that identifies the declared class as a * return type for the method represented by the given {@code String name} * parameter inside the invoked {@code Class<?> clazz} parameter. * * @param clazz * the {@code Class} object whose declared methods to be checked * for the wanted method name. * @param name * the method name as {@code String} to be compared with * {@link Method#getName()} * @return the {@code Class} object representing the return type of the * given method name. * * @see {@link Class#getDeclaredMethods()} * @see {@link Method#getReturnType()} */ public static Class<?> getMethodReturnType(Class<?> clazz, String name) { if (clazz == null || name == null || name.isEmpty()) { return null; } name = name.toLowerCase(); Class<?> returnType = null; for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals(name)) { returnType = method.getReturnType(); break; } } return returnType; } }