Here you can find the source of getSetterMethod(Class containingClass, Class propertyType, String propertyName)
Parameter | Description |
---|---|
containingClass | never null |
propertyType | never null |
propertyName | never null |
public static Method getSetterMethod(Class containingClass, Class propertyType, String propertyName)
//package com.java2s; /*/* www .j a va 2 s . c o m*/ * Copied from the Hibernate Validator project * Original authors: Hardy Ferentschik, Gunnar Morling and Kevin Pollet. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.lang.reflect.Method; public class Main { private static final String PROPERTY_MUTATOR_PREFIX = "set"; /** * @param containingClass never null * @param propertyType never null * @param propertyName never null * @return null if it doesn't exist */ public static Method getSetterMethod(Class containingClass, Class propertyType, String propertyName) { String setterName = PROPERTY_MUTATOR_PREFIX + (propertyName.isEmpty() ? "" : propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1)); try { return containingClass.getMethod(setterName, propertyType); } catch (NoSuchMethodException e) { return null; } } }