集册 Java实例教程 获取类突变器方法

获取类突变器方法

欢马劈雪     最近更新时间:2020-01-02 10:19:05

565
获取类突变器方法


import java.lang.reflect.Method;


public class Main{
/**
nowjava.com - 时  代  Java
**/

    public static void main(String[] argv) throws Exception{

        Class clazz = String.class;

        String propertyName = "nowjava.com";

        Class params = String.class;

        System.out.println(getMutator(clazz,propertyName,params));

    }

    public static final String[] MUTATOR_PREFIXES = new String[] { "set" };

    public static Method getMutator(Class clazz, String propertyName,

            Class... params) {

        propertyName = StringHelper.capitalize(propertyName);/*NowJava.com - 时代Java*/

        for (String prefix : MUTATOR_PREFIXES) {

            try {

                return clazz.getDeclaredMethod(prefix + propertyName,

       
展开阅读全文