集册 Java实例教程 解析Getter

解析Getter

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

483
解析Getter


//package com.nowjava;

import java.lang.reflect.Method;/** 来 自 NowJava.com - 时代Java**/


public class Main {

    private static final String GET_PREFIX = "get";

    private static final String IS_PREFIX = "is";


    public static Method parseGetter(Object bean, String propertyName,

            Class<?> propertyClass) throws SecurityException,

            NoSuchMethodException {

        return bean.getClass().getMethod(

                getGetMethodName(propertyName, propertyClass));


    }


    public static String getGetMethodName(String propertyName,

            Class<?> propertyClass) {

        if (propertyClass == boolean.class) {/** from n o w  j a v a  . c o m**/

            return IS_PREFIX + capitalizeMethodName(propertyName);

        } else if (propertyClass == Boolean.class) {

            return IS_PREFIX + capitalizeMethodName(propertyName);

        } else {

            return GET_PREFIX + capitalizeMethodName(propertyName);

        }

    }


    private static 
展开阅读全文