is Getter Method - Android java.lang.reflect

Android examples for java.lang.reflect:Method Getter Setter

Description

is Getter Method

Demo Code


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

public class Main {
    static boolean isGetter(Method method) {
        return !(method == null || "getId".equals(method.getName())
                || "isTransient".equals(method.getName()) || "isPersistent"
                    .equals(method.getName()))
                && (isBooleanGetter(method) || method.getName().startsWith(
                        "get")
                        && method.getName().length() > 3
                        && method.getReturnType() != Void.class
                        && method.getParameterTypes().length == 0
                        && !Modifier.isStatic(method.getModifiers())
                        && Modifier.isPublic(method.getModifiers()));

    }/*w  ww  . ja va2  s.co m*/

    static boolean isBooleanGetter(Method method) {
        return method != null
                && method.getName().startsWith("is")
                && method.getName().length() > 2
                && (method.getReturnType() == boolean.class || method
                        .getReturnType() == Boolean.class);
    }
}

Related Tutorials