List of utility methods to do Reflection Method Get from Object
Method | getMethod(Object instance, String methodName, Class[] parameters) get Method return getMethod(instance.getClass(), methodName, parameters);
|
Method | getMethod(Object o, String methodName) get Method if ((methodName == null) || (o == null)) { return null; Method[] ms = o.getClass().getMethods(); for (int i = 0; i < ms.length; i++) { Method m = ms[i]; if (m.getName().equals(methodName)) { return m; ... |
Method | getMethod(Object o, String methodName, Class>[] args) get Method return getMethod(o.getClass(), methodName, args);
|
Method | getMethod(Object o, String methodName, Class[] paramTypes) get Method Class clz = o.getClass();
return clz.getMethod(methodName, paramTypes);
|
Method | getMethod(Object obj, Class[] paramTypes, String methodName) Get the method given in string in input corresponding to the given arguments. Method method = obj.getClass().getMethod(methodName, paramTypes);
return method;
|
Method | getMethod(Object obj, String fieldName) Get a field in an object. try { Method method = obj.getClass().getMethod("get" + fieldName); return method; } catch (Exception t) { return null; |
Method | getMethod(Object obj, String methodName) get Method Method[] ms = obj.getClass().getMethods(); for (Method m : ms) { if (m.getName().equals(methodName)) { return m; if (methodName.contains("_")) { String[] nameSet = methodName.split("_"); ... |
Method | getMethod(Object obj, String methodName, Class paramClass) get Method return getMethod(obj, methodName, new Class[] { paramClass }); |
Method | getMethod(Object obj, String methodName, Class>... parameterTypes) get Method try { Method method = getClass(obj).getDeclaredMethod(methodName, parameterTypes); method.setAccessible(true); return method; } catch (Exception e) { e.printStackTrace(); return null; |
Method | getMethod(Object obj, String name, Class... types) Easy way to get accessible methods from inherited children Class c = obj.getClass(); while (c != Object.class) { try { Method m = c.getDeclaredMethod(name, types); m.setAccessible(true); return m; } catch (NoSuchMethodException e) { c = c.getSuperclass(); ... |