集册 Java实例教程 找到塞特犬

找到塞特犬

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

459
找到塞特犬
/**n o w j a v a . c o m - 时代Java**/


import java.lang.reflect.Method;

import org.apache.log4j.Logger;


public class Main{

    public static Method findSetter(Class<?> onClass, String field) {

        String methodName = "set" + field.substring(0, 1).toUpperCase()

                + field.substring(1);

        Method[] methods = onClass.getMethods();

        for (int i = 0; i < methods.length; i++) {

            Method method = methods[i];

            if (method.getName().equals(methodName)) {

                return method;

            }

        }

        methodName = field;

        for (int i = 0; i < methods.length; i++) {

            Method method = methods[i];

            if (method.getNam
展开阅读全文