java.lang.reflect

Class Modifier


public class Modifier
extends Object

Modifier is a helper class with static methods to determine whether an int returned from getModifiers() represents static, public, protected, native, final, etc... and provides an additional method to print out all of the modifiers in an int in order.

The methods in this class use the bitmask values in the VM spec to determine the modifiers of an int. This means that a VM must return a standard mask, conformant with the VM spec. I don't know if this is how Sun does it, but I'm willing to bet money that it is.

Since:
1.1
See Also:
Member.getModifiers(), Method.getModifiers(), Field.getModifiers(), Constructor.getModifiers(), Class.getModifiers()

Field Summary

static int
ABSTRACT
Abstract:
  • Class: may not be instantiated.
  • Method: may not be called.
static int
FINAL
Final:
  • Class: no subclasses allowed.
  • Field: cannot be changed.
  • Method: cannot be overriden.
static int
INTERFACE
Interface: Class: is an interface.
static int
NATIVE
Native: Method: use JNI to call this method.
static int
PRIVATE
Private: accessible only from the same enclosing class.
static int
PROTECTED
Protected: accessible only to subclasses, or within the package.
static int
PUBLIC
Public: accessible from any other class.
static int
STATIC
Static:
  • Class: no enclosing instance for nested class.
  • Field or Method: can be accessed or invoked without an instance of the declaring class.
static int
STRICT
Strictfp: Method: expressions are FP-strict.

Also used as a modifier for classes, to mean that all initializers and constructors are FP-strict, but does not show up in Class.getModifiers.

static int
SYNCHRONIZED
Synchronized: Method: lock the class while calling this method.
static int
TRANSIENT
Transient: Field: not serialized or deserialized.
static int
VOLATILE
Volatile: Field: cannot be cached.

Constructor Summary

Modifier()
This constructor really shouldn't be here ... there are no instance methods or variables of this class, so instantiation is worthless.

Method Summary

static int
classModifiers()
static int
constructorModifiers()
static int
fieldModifiers()
static int
interfaceModifiers()
static boolean
isAbstract(int mod)
Check whether the given modifier is abstract.
static boolean
isFinal(int mod)
Check whether the given modifier is final.
static boolean
isInterface(int mod)
Check whether the given modifier is an interface.
static boolean
isNative(int mod)
Check whether the given modifier is native.
static boolean
isPrivate(int mod)
Check whether the given modifier is private.
static boolean
isProtected(int mod)
Check whether the given modifier is protected.
static boolean
isPublic(int mod)
Check whether the given modifier is public.
static boolean
isStatic(int mod)
Check whether the given modifier is static.
static boolean
isStrict(int mod)
Check whether the given modifier is strictfp.
static boolean
isSynchronized(int mod)
Check whether the given modifier is synchronized.
static boolean
isTransient(int mod)
Check whether the given modifier is transient.
static boolean
isVolatile(int mod)
Check whether the given modifier is volatile.
static int
methodModifiers()
static String
toString(int mod)
Get a string representation of all the modifiers represented by the given int.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

ABSTRACT

public static final int ABSTRACT
Abstract:
  • Class: may not be instantiated.
  • Method: may not be called.
Field Value:
1024

FINAL

public static final int FINAL
Final:
  • Class: no subclasses allowed.
  • Field: cannot be changed.
  • Method: cannot be overriden.
Field Value:
16

INTERFACE

public static final int INTERFACE
Interface: Class: is an interface.
Field Value:
512

NATIVE

public static final int NATIVE
Native: Method: use JNI to call this method.
Field Value:
256

PRIVATE

public static final int PRIVATE
Private: accessible only from the same enclosing class.
Field Value:
2

PROTECTED

public static final int PROTECTED
Protected: accessible only to subclasses, or within the package.
Field Value:
4

PUBLIC

public static final int PUBLIC
Public: accessible from any other class.
Field Value:
1

STATIC

public static final int STATIC
Static:
  • Class: no enclosing instance for nested class.
  • Field or Method: can be accessed or invoked without an instance of the declaring class.
Field Value:
8

STRICT

public static final int STRICT
Strictfp: Method: expressions are FP-strict.

Also used as a modifier for classes, to mean that all initializers and constructors are FP-strict, but does not show up in Class.getModifiers.

Field Value:
2048

SYNCHRONIZED

public static final int SYNCHRONIZED
Synchronized: Method: lock the class while calling this method.
Field Value:
32

TRANSIENT

public static final int TRANSIENT
Transient: Field: not serialized or deserialized.
Field Value:
128

VOLATILE

public static final int VOLATILE
Volatile: Field: cannot be cached.
Field Value:
64

Constructor Details

Modifier

public Modifier()
This constructor really shouldn't be here ... there are no instance methods or variables of this class, so instantiation is worthless. However, this function is in the 1.1 spec, so it is added for completeness.

Method Details

classModifiers

public static int classModifiers()
Since:
1.7

constructorModifiers

public static int constructorModifiers()
Since:
1.7

fieldModifiers

public static int fieldModifiers()
Since:
1.7

interfaceModifiers

public static int interfaceModifiers()
Since:
1.7

isAbstract

public static boolean isAbstract(int mod)
Check whether the given modifier is abstract.
Parameters:
mod - the modifier.
Returns:
true if abstract, false otherwise.

isFinal

public static boolean isFinal(int mod)
Check whether the given modifier is final.
Parameters:
mod - the modifier.
Returns:
true if final, false otherwise.

isInterface

public static boolean isInterface(int mod)
Check whether the given modifier is an interface.
Parameters:
mod - the modifier.
Returns:
true if an interface, false otherwise.

isNative

public static boolean isNative(int mod)
Check whether the given modifier is native.
Parameters:
mod - the modifier.
Returns:
true if native, false otherwise.

isPrivate

public static boolean isPrivate(int mod)
Check whether the given modifier is private.
Parameters:
mod - the modifier.
Returns:
true if private, false otherwise.

isProtected

public static boolean isProtected(int mod)
Check whether the given modifier is protected.
Parameters:
mod - the modifier.
Returns:
true if protected, false otherwise.

isPublic

public static boolean isPublic(int mod)
Check whether the given modifier is public.
Parameters:
mod - the modifier.
Returns:
true if public, false otherwise.

isStatic

public static boolean isStatic(int mod)
Check whether the given modifier is static.
Parameters:
mod - the modifier.
Returns:
true if static, false otherwise.

isStrict

public static boolean isStrict(int mod)
Check whether the given modifier is strictfp.
Parameters:
mod - the modifier.
Returns:
true if strictfp, false otherwise.

isSynchronized

public static boolean isSynchronized(int mod)
Check whether the given modifier is synchronized.
Parameters:
mod - the modifier.
Returns:
true if synchronized, false otherwise.

isTransient

public static boolean isTransient(int mod)
Check whether the given modifier is transient.
Parameters:
mod - the modifier.
Returns:
true if transient, false otherwise.

isVolatile

public static boolean isVolatile(int mod)
Check whether the given modifier is volatile.
Parameters:
mod - the modifier.
Returns:
true if volatile, false otherwise.

methodModifiers

public static int methodModifiers()
Since:
1.7

toString

public static String toString(int mod)
Get a string representation of all the modifiers represented by the given int. The keywords are printed in this order: <public|protected|private> abstract static final transient volatile synchronized native strictfp interface.
Parameters:
mod - the modifier.
Returns:
the String representing the modifiers.

java.lang.reflect.Modifier Copyright (C) 1998, 1999, 2001, 2002, 2005, 2008, 2012 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath 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 for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.