Here you can find the source of getSetter(Object target, String property, Class> parameterType)
Parameter | Description |
---|---|
target | target object |
property | property |
parameterType | setter parameter type |
public static Method getSetter(Object target, String property, Class<?> parameterType)
//package com.java2s; /*//www .ja v a2s . c o m * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. */ import java.lang.reflect.Method; public class Main { /** * Get setter method * * @param target target object * @param property property * @param parameterType setter parameter type * * @return setter method */ public static Method getSetter(Object target, String property, Class<?> parameterType) { String setterMethodName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1); Method setter = getMethod(target, setterMethodName, parameterType); setter.setAccessible(true); return setter; } /** * Get target method * * @param target target object * @param methodName method name * @param parameterTypes method parameter types * * @return return value */ public static Method getMethod(Object target, String methodName, Class... parameterTypes) { try { return target.getClass().getMethod(methodName, parameterTypes); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(e); } } }