List of utility methods to do Reflection Method Get from Object
Method | getMethodWithExactName(Class extends Object> clazz, String name) Looks up a method having the specified name within a class. for (Method m : clazz.getMethods()) { if (m.getName().equals(name)) { return m; throw new NoSuchMethodException(); |
Optional | getMethodWithPrefix(final Object o, final String fieldName, final String prefix) Returns any method whose name starts with given prefix and ends with given fieldname where first letter of the fieldname will be uppercased. final String methodName = prefix + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1); return Arrays.stream(o.getClass().getMethods()).filter(method -> method.getName().equals(methodName)) .findFirst(); |