Here you can find the source of getGetter(Object object, String name)
Parameter | Description |
---|---|
object | container of setter |
name | name of property |
public static Method getGetter(Object object, String name)
//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 ww .j av a 2 s. c o m*/ * get getter by name * * @param object container of setter * @param name name of property * @return requester getter */ public static Method getGetter(Object object, String name) { String getterName = "get" + capitaliseName(name); return getMethod(object, getterName); } 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; } }