List of utility methods to do Reflection Method Return
Class | getMethodGenericReturnType(Method method, int index) get Method Generic Return Type Type returnType = method.getGenericReturnType(); if (returnType instanceof ParameterizedType) { ParameterizedType type = (ParameterizedType) returnType; Type[] typeArguments = type.getActualTypeArguments(); if (index >= typeArguments.length || index < 0) { throw new IllegalArgumentException("index " + (index < 0 ? " must > 0 " : " over total arguments")); return (Class) typeArguments[index]; ... |
Function | getMethodInvoker(final Class get Method Invoker return new Function<Object, T>() { public T apply(Object from) { if (from == null) return null; try { Method method = from.getClass().getMethod(methodName, new Class[0]); return returnType.cast(method.invoke(from, new Object[0])); } catch (SecurityException e) { ... |
Method | getMethodNoArgs(final Class> objClass, final String methodName, final Class>... returnTypePreference) Direct getMethod attempt. try { final Method methodFound = objClass.getMethod(methodName); if (methodFound != null) { if (returnTypePreference == null || returnTypePreference.length == 0) { return methodFound; final Class<?> returnType = methodFound.getReturnType(); for (int i = 0; i < returnTypePreference.length; i++) { ... |
Class> | getMethodReturnType(Class> clazz, String methodName) Returns return type of given method in given class. try { Method method = clazz.getDeclaredMethod(methodName); return method.getReturnType(); } catch (NoSuchMethodException e) { throw new AssertionError(e); } catch (SecurityException e) { throw new AssertionError(e); |
Class> | getMethodReturnType(Class> clazz, String name) Returns a Class object that identifies the declared class as a return type for the method represented by the given String name parameter inside the invoked Class> clazz parameter. 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(); ... |
Class> | getMethodReturnType(Class> clazz, String name) get Method Return Type 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(); ... |