Indicates whether or not the given class or method is abstract. - Java Reflection

Java examples for Reflection:Access modifier

Description

Indicates whether or not the given class or method is abstract.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int access = 2;
        System.out.println(isAbstract(access));
    }/*from   w w  w .j  a v  a  2 s .  c o m*/

    /**
     * The access flag mask for the <code>abstract</code> keyword. This
     * keyword is usually also present with the
     * {@link ByteCodeUtils#ACCESS_INTERFACE}
     * and
     * {@link ByteCodeUtils#ACCESS_ANNOTATION}
     * flags for classes. In both of these cases, this flag will be
     * ignored as both of those types infer <code>abstract</code>. This
     * will only be present in method and class access flags.
     *
     * @see ByteCodeUtils#isAbstract(int)
     */
    private static final int ACCESS_ABSTRACT = 0x0400;

    /**
     * Indicates whether or not the given class or method is
     * <code>abstract</code>.
     * <p>
     * For <code>interface</code> types and <code>annotation</code> types,
     * this is inferred and therefore may not appear in the access flag
     * names even if set.
     * <p>
     * Although it is also true that this is inferred for the methods of
     * said types, it cannot be ensured and therefore this will appear in
     * the method access flag names for <code>interface</code> types and
     * for <code>annotation</code> types.
     *
     * @param access The access flags for the class or method.
     * @return <code>true</code> if and only if the access flags indicate
     * the class or method is <code>abstract</code>.
     * @see ByteCodeUtils#ACCESS_ABSTRACT
     */

    public static boolean isAbstract(final int access) {
        return (access & ACCESS_ABSTRACT) != 0;
    }
}

Related Tutorials