Here you can find the source of getSetter(Object object, String name, Class type)
Parameter | Description |
---|---|
object | container of getter |
name | name of property |
type | type of property |
public static Method getSetter(Object object, String name, Class type)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; public class Main { /***//from w w w. j a v a 2 s .c o m * get setter method by property name * * @param object container of getter * @param name name of property * @param type type of property * @return requested setter */ public static Method getSetter(Object object, String name, Class type) { String setterName = "set" + capitaliseName(name); return getMethod(object, setterName, type); } private static String capitaliseName(String name) { return name.substring(0, 1).toUpperCase() + name.substring(1); } /*** * get method by name * * @param object container of method * @param name name of method * @param params params of method * @return requested method */ public static Method getMethod(Object object, String name, Object... params) { try { List<Class> classParams = new ArrayList<>(); for (int i = 0; i < params.length; i++) { classParams.add((Class) params[i]); } Class<?> classParamsArray[] = new Class[classParams.size()]; classParams.toArray(classParamsArray); return object.getClass().getMethod(name, classParamsArray); } catch (NoSuchMethodException e) { } return null; } }