is setter Method - Java Reflection

Java examples for Reflection:Setter

Description

is setter Method

Demo Code


//package com.java2s;
import java.lang.reflect.Method;

public class Main {

    public static final int SET_START = "set".length();

    public static boolean isSetter(Method method) {
        String name = method.getName();
        boolean hasOneParam = method.getParameterTypes().length == 1;
        boolean startsWithGet = (name.length() > SET_START)
                && name.startsWith("set");

        return startsWithGet && hasOneParam;
    }/*from  w  ww.  j av a  2s  . c o m*/
}

Related Tutorials