Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Oracle in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 package java.lang.reflect;
 
The Modifier class provides static methods and constants to decode class and member access modifiers. The sets of modifiers are represented as integers with distinct bit positions representing different modifiers. The values for the constants representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of The Java™ Virtual Machine Specification.

Author(s):
Nakul Saraiya
Kenneth Russell
See also:
java.lang.Class.getModifiers()
Member.getModifiers()
 
 public
 class Modifier {
 
     /*
      * Bootstrapping protocol between java.lang and java.lang.reflect
      *  packages
      */
     static {
         sun.reflect.ReflectionFactory factory =
             AccessController.doPrivileged(
                 new ReflectionFactory.GetReflectionFactoryAction());
         factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
     }

    
Return true if the integer argument includes the public modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the public modifier; false otherwise.
 
     public static boolean isPublic(int mod) {
         return (mod & ) != 0;
     }

    
Return true if the integer argument includes the private modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the private modifier; false otherwise.
 
     public static boolean isPrivate(int mod) {
         return (mod & ) != 0;
     }

    
Return true if the integer argument includes the protected modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the protected modifier; false otherwise.
 
     public static boolean isProtected(int mod) {
         return (mod & ) != 0;
     }

    
Return true if the integer argument includes the static modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the static modifier; false otherwise.
    public static boolean isStatic(int mod) {
        return (mod & ) != 0;
    }

    
Return true if the integer argument includes the final modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the final modifier; false otherwise.
    public static boolean isFinal(int mod) {
        return (mod & ) != 0;
    }

    
Return true if the integer argument includes the synchronized modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the synchronized modifier; false otherwise.
    public static boolean isSynchronized(int mod) {
        return (mod & ) != 0;
    }

    
Return true if the integer argument includes the volatile modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the volatile modifier; false otherwise.
    public static boolean isVolatile(int mod) {
        return (mod & ) != 0;
    }

    
Return true if the integer argument includes the transient modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the transient modifier; false otherwise.
    public static boolean isTransient(int mod) {
        return (mod & ) != 0;
    }

    
Return true if the integer argument includes the native modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the native modifier; false otherwise.
    public static boolean isNative(int mod) {
        return (mod & ) != 0;
    }

    
Return true if the integer argument includes the interface modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the interface modifier; false otherwise.
    public static boolean isInterface(int mod) {
        return (mod & ) != 0;
    }

    
Return true if the integer argument includes the abstract modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the abstract modifier; false otherwise.
    public static boolean isAbstract(int mod) {
        return (mod & ) != 0;
    }

    
Return true if the integer argument includes the strictfp modifier, false otherwise.

Parameters:
mod a set of modifiers
Returns:
true if mod includes the strictfp modifier; false otherwise.
    public static boolean isStrict(int mod) {
        return (mod & ) != 0;
    }

    
Return a string describing the access modifier flags in the specified modifier. For example:
    public final synchronized strictfp
 
The modifier names are returned in an order consistent with the suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of The Java™ Language Specification. The full modifier ordering used by this method is:
public protected private abstract static final transient volatile synchronized native strictfp interface
The interface modifier discussed in this class is not a true modifier in the Java language and it appears after all other modifiers listed by this method. This method may return a string of modifiers that are not valid modifiers of a Java entity; in other words, no checking is done on the possible validity of the combination of modifiers represented by the input. Note that to perform such checking for a known kind of entity, such as a constructor or method, first AND the argument of toString with the appropriate mask from a method like constructorModifiers() or methodModifiers().

Parameters:
mod a set of modifiers
Returns:
a string representation of the set of modifiers represented by mod
    public static String toString(int mod) {
        StringBuffer sb = new StringBuffer();
        int len;
        if ((mod & ) != 0)        sb.append("public ");
        if ((mod & ) != 0)     sb.append("protected ");
        if ((mod & ) != 0)       sb.append("private ");
        /* Canonical order */
        if ((mod & ) != 0)      sb.append("abstract ");
        if ((mod & ) != 0)        sb.append("static ");
        if ((mod & ) != 0)         sb.append("final ");
        if ((mod & ) != 0)     sb.append("transient ");
        if ((mod & ) != 0)      sb.append("volatile ");
        if ((mod & ) != 0)  sb.append("synchronized ");
        if ((mod & ) != 0)        sb.append("native ");
        if ((mod & ) != 0)        sb.append("strictfp ");
        if ((mod & ) != 0)     sb.append("interface ");
        if ((len = sb.length()) > 0)    /* trim trailing space */
            return sb.toString().substring(0, len-1);
        return "";
    }
    /*
     * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
     * <cite>The Java&trade; Virtual Machine Specification</cite>
     */

    
The int value representing the public modifier.
    public static final int PUBLIC           = 0x00000001;

    
The int value representing the private modifier.
    public static final int PRIVATE          = 0x00000002;

    
The int value representing the protected modifier.
    public static final int PROTECTED        = 0x00000004;

    
The int value representing the static modifier.
    public static final int STATIC           = 0x00000008;

    
The int value representing the final modifier.
    public static final int FINAL            = 0x00000010;

    
The int value representing the synchronized modifier.
    public static final int SYNCHRONIZED     = 0x00000020;

    
The int value representing the volatile modifier.
    public static final int VOLATILE         = 0x00000040;

    
The int value representing the transient modifier.
    public static final int TRANSIENT        = 0x00000080;

    
The int value representing the native modifier.
    public static final int NATIVE           = 0x00000100;

    
The int value representing the interface modifier.
    public static final int INTERFACE        = 0x00000200;

    
The int value representing the abstract modifier.
    public static final int ABSTRACT         = 0x00000400;

    
The int value representing the strictfp modifier.
    public static final int STRICT           = 0x00000800;
    // Bits not (yet) exposed in the public API either because they
    // have different meanings for fields and methods and there is no
    // way to distinguish between the two in this class, or because
    // they are not Java programming language keywords
    static final int BRIDGE    = 0x00000040;
    static final int VARARGS   = 0x00000080;
    static final int SYNTHETIC = 0x00001000;
    static final int ANNOTATION= 0x00002000;
    static final int ENUM      = 0x00004000;
    static boolean isSynthetic(int mod) {
      return (mod & ) != 0;
    }

    
See JLSv3 section 8.1.1.
    private static final int CLASS_MODIFIERS =
        .         | .    | . |
        .       | .       | .   |
        .;

    
See JLSv3 section 9.1.1.
    private static final int INTERFACE_MODIFIERS =
        .         | .    | . |
        .       | .       | .;


    
See JLSv3 section 8.8.3.
    private static final int CONSTRUCTOR_MODIFIERS =
        .         | .    | .;

    
See JLSv3 section 8.4.3.
    private static final int METHOD_MODIFIERS =
        .         | .    | . |
        .       | .       | .   |
        .   | .       | .;

    
See JLSv3 section 8.3.1.
    private static final int FIELD_MODIFIERS =
        .         | .    | . |
        .         | .        | . |
        .;

    
Return an int value OR-ing together the source language modifiers that can be applied to a class.

Returns:
an int value OR-ing together the source language modifiers that can be applied to a class.
Since:
1.7
Jls:
8.1.1 Class Modifiers
    public static int classModifiers() {
        return ;
    }

    
Return an int value OR-ing together the source language modifiers that can be applied to an interface.

Returns:
an int value OR-ing together the source language modifiers that can be applied to an inteface.
Since:
1.7
Jls:
9.1.1 Interface Modifiers
    public static int interfaceModifiers() {
        return ;
    }

    
Return an int value OR-ing together the source language modifiers that can be applied to a constructor.

Returns:
an int value OR-ing together the source language modifiers that can be applied to a constructor.
Since:
1.7
Jls:
8.8.3 Constructor Modifiers
    public static int constructorModifiers() {
        return ;
    }

    
Return an int value OR-ing together the source language modifiers that can be applied to a method.

Returns:
an int value OR-ing together the source language modifiers that can be applied to a method.
Since:
1.7
Jls:
8.4.3 Method Modifiers
    public static int methodModifiers() {
        return ;
    }


    
Return an int value OR-ing together the source language modifiers that can be applied to a field.

Returns:
an int value OR-ing together the source language modifiers that can be applied to a field.
Since:
1.7
Jls:
8.3.1 Field Modifiers
    public static int fieldModifiers() {
        return ;
    }
New to GrepCode? Check out our FAQ X