Java Utililty Methods Reflection Method Return

List of utility methods to do Reflection Method Return

  1. HOME
  2. Java
  3. R
  4. Reflection Method Return

Description

The list of methods to do Reflection Method Return are organized into topic(s).

Method

Method getMethod(Class clazz, String methodName, Class returnType, Class... inputParams)
get Method
if (inputParams == null) {
 inputParams = new Class<?>[0];
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
 if (method.getName().equals(methodName) && returnType.isAssignableFrom(method.getReturnType())
 && Arrays.equals(inputParams, method.getParameterTypes())) {
 return method;
...
Method getMethod(Class clazz, String name, String returnType, String[] args)
get Method
Method[] methods = clazz.getDeclaredMethods();
MainLoop: for (Method method : methods) {
 if (name != null && !name.equals(method.getName())) {
 continue;
 if (returnType != null && !returnType.equals(method.getReturnType().getName())) {
 continue;
 if (args != null) {
 Class<?>[] args2 = method.getParameterTypes();
 if (args2.length != args.length) {
 continue;
 for (int count = 0; count < args.length; count++) {
 if (!(args[count].equals(args2[count].getName()))) {
 continue MainLoop;
 return method;
return null;
Method getMethod(Class parentClass, Class returnType, String methodName, Class... types)
get Method
for (Method method : parentClass.getDeclaredMethods()) {
 if (equalsTo(method, returnType, methodName, types))
 return method;
return null;
Method getMethod(Class type, String name, Class returnType, Class paramType, boolean caseSensitive)
Gets the public method within the type that matches the method name, return type, and single parameter type.
boolean methodNameFound = false;
Class<?> classType = type;
while (classType != null && !classType.equals(Object.class)) {
 for (Method m : classType.getDeclaredMethods()) {
 if ((!caseSensitive && m.getName().equalsIgnoreCase(name))
 || (caseSensitive && m.getName().equals(name))) {
 methodNameFound = true;
 if (returnType != null) {
...
Method getMethodByReturnType(final Class source, final Class type)
get Method By Return Type
for (final Method e : source.getDeclaredMethods()) {
 if (e.getReturnType().isAssignableFrom(type)) {
 return e;
return null;
Method getMethodByTypes(Class clazz, String name, Class returnType, Class... parameterTypes)
get Method By Types
for (Method method : clazz.getDeclaredMethods()) {
 if (!Modifier.isPublic(method.getModifiers())) {
 continue;
 if (method.getReturnType().equals(returnType)
 && Arrays.equals(method.getParameterTypes(), parameterTypes)) {
 return method;
throw new RuntimeException(name + " not found in " + clazz);
String getMethodDesc(Class returnType, Class... params)
get Method Desc
StringBuilder sb = new StringBuilder("(");
for (Class<?> c : params) {
 sb.append(getDesc(c));
sb.append(')');
sb.append(getDesc(returnType));
return sb.toString();
Method getMethode(Class clasS, Class Returntype, int modifier, Class... classes)
get Methode
for (Method m : clasS.getDeclaredMethods()) {
 if (HasParametersignature(m, classes) && m.getReturnType().isAssignableFrom(Returntype)
 && m.getModifiers() == modifier)
 return m;
return null;
Class getMethodGenericReturnType(Method method, Class rawType, int index)
get Method Generic Return Type
Type returnType = method.getGenericReturnType();
return getGenericType(returnType, rawType, index);
Class getMethodGenericReturnType(Method method, int index)
get Method Generic Return Type
return getGenericType(method.getGenericReturnType(), index);


AltStyle によって変換されたページ (->オリジナル) /