Returns true if the given method object corresponds to a "is". - Java Reflection

Java examples for Reflection:Method

Description

Returns true if the given method object corresponds to a "is".

Demo Code

/**/*w w w.ja v  a2 s  .  co m*/
 * A utility class that performs various operations using the Java reflection
 * API.
 * 
 * @author Yanick Duchesne
 *         <dl>
 *         <dt><b>Copyright: </b>
 *         <dd>Copyright &#169; 2002-2003 <a
 *         href="http://www.sapia-oss.org">Sapia Open Source Software </a>. All
 *         Rights Reserved.</dd>
 *         </dt>
 *         <dt><b>License: </b>
 *         <dd>Read the license.txt file of the jar or visit the <a
 *         href="http://www.sapia-oss.org/license.html">license page </a> at the
 *         Sapia OSS web site</dd>
 *         </dt>
 *         </dl>
 */
//package com.java2s;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Main {
    /**
     * Returns <code>true</code> if the given method object corresponds to a
     * "is". The method must start with a "is" prefix and be non-static, public,
     * take no parameter, and have a boolean return type.
     * 
     * @param method
     *          a <code>Method</code> object.
     * @return <code>true</code> if the given instance corresponds to a "is".
     */
    public static boolean isBoolean(Method method) {
        return method.getName().startsWith("is")
                && Modifier.isPublic(method.getModifiers())
                && !Modifier.isStatic(method.getModifiers())
                && (method.getParameterTypes().length == 0)
                && (method.getReturnType() != null)
                && !method.getReturnType().equals(void.class);
    }
}

Related Tutorials