List of utility methods to do Reflection Method Setter Get
Method | getSetter(A instance, String strAttributeName, Class> clazz) Gets the setter. return getMethod(PREFIX_SET, instance, strAttributeName, clazz);
|
Method | getSetter(Class _class, String fieldName) get Setter return getSetter(gatherAllBeanFields(_class).get(fieldName)); |
Method | getSetter(Class clazz, String name) Get a setter with a given name from a class. Method[] methods = clazz.getMethods(); Method setter = null; for (int i = 0; i < methods.length; i++) { if (isSetter(methods[i]) && name.equals(methods[i].getName())) { setter = methods[i]; break; return setter; |
Method | getSetter(Class> clazz, Field field) get Setter Method setter = clazz.getMethod(getSetterName(field), field.getType()); if (!setter.getReturnType().equals(void.class)) { throw new NoSuchMethodException(); return setter; |
Method | getSetter(Class> clazz, Field field) get Setter Class<?> fieldType = field.getType(); String filedName = field.getName(); String firstLetter = filedName.substring(0, 1).toUpperCase(); String setMethodName = "set" + firstLetter + filedName.substring(1); Method setMethod = null; try { setMethod = clazz.getDeclaredMethod(setMethodName, fieldType); } catch (Exception e) { ... |
Method | getSetter(Class> clazz, String property, Class> type) get Setter String setterName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1); try { Method method = clazz.getDeclaredMethod(setterName, type); return method; } catch (NoSuchMethodException e) { throw new IllegalArgumentException("no setter found for property '" + property + "'", e); |
Method | getSetter(Class get Setter for (final Method method : cls.getMethods()) { if (method.getName().equalsIgnoreCase("set" + fieldName) && method.getParameters().length == 1) { if (!method.isAccessible()) { method.setAccessible(true); return method; return null; |
Method | getSetter(final Class targetClass, final String propertyName) get Setter String setterName = "set" + Character.toUpperCase(propertyName.charAt(0)); if (setterName.length() > 1) setterName += propertyName.substring(1); final Method[] methods = targetClass.getMethods(); for (Method m : methods) { if (m.getName().equals(setterName) && m.getParameterTypes().length == 1) return m; return null; |
Method | getSetter(final Class> clazz, final String fieldName, final Class>... fieldClass) get Setter final String methodName = "set" + capitalize(fieldName); try { final Method method = clazz.getDeclaredMethod(methodName, fieldClass); method.setAccessible(true); return method; } catch (SecurityException | NoSuchMethodException e) { return null; ... |
Method | getSetter(final Class> clz, final String propertyName, final Class> propertyClass) get Setter final Class<?> setterArgs[] = new Class[1]; setterArgs[0] = propertyClass; final String setterName = "set" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); return clz.getMethod(setterName, setterArgs); |