is Accessor Method - Java Reflection

Java examples for Reflection:Method

Description

is Accessor Method

Demo Code


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

public class Main {
    public static final String[] ACCESSOR_PREFIXES = new String[] { "is",
            "get", "has" };

    public static boolean isAccessor(Method method) {
        for (String prefix : ACCESSOR_PREFIXES) {
            if (method.getName().startsWith(prefix)
                    && method.getParameterTypes().length == 0
                    && method.getReturnType() != null)
                return true;
        }//from w w w. ja va2  s.  co  m
        return false;
    }
}

Related Tutorials