Java. Lang. Reflect. Modifier

Source: Internet
Author: User

Package java. Lang. Reflect;

Import java. Security. accesscontroller;
Import sun. Reflect. langreflectaccess;
Import sun. Reflect. reflectionfactory;

/**
*
* Used to determine the element type. The element type is an int-type number, and its bit represents different descriptors.
*
* Comment by liqiang
*
* @ Author nakul saraiya
* @ Author kenth Russell
*/
Public
Class modifier {

/*
* Bootstrapping protocol between Java. Lang and Java. Lang. Reflect
* Packages
*/
Static {
Sun. Reflect. reflectionfactory factory =
(Sun. Reflect. reflectionfactory) accesscontroller. doprivileged (
New reflectionfactory. getreflectionfactoryaction ()
);
Factory. setlangreflectaccess (New java. Lang. Reflect. reflectaccess ());
}

// Whether the object contains the public Descriptor
Public static Boolean ispublic (INT mod ){
// Judge whether the public bit is 1, except that the public bit is 0
// Perform the bitwise AND operation. If the public bit is 1, the result is 1. Otherwise, the result is 0.
Return (mod & Public )! = 0;
}

// Whether the private descriptor is contained
Public static Boolean isprivate (INT mod ){
Return (mod & private )! = 0;
}

// Whether it contains the protected Descriptor
Public static Boolean isprotected (INT mod ){
Return (mod & protected )! = 0;
}

// Whether the object contains the static Descriptor
Public static Boolean isstatic (INT mod ){
Return (mod & Static )! = 0;
}

// Whether the final descriptor is contained
Public static Boolean isfinal (INT mod ){
Return (mod & final )! = 0;
}

// Whether synchronized descriptor is contained
Public static Boolean issynchronized (INT mod ){
Return (mod & synchronized )! = 0;
}

// Whether it contains the volatile Descriptor
Public static Boolean isvolatile (INT mod ){
Return (mod & volatile )! = 0;
}

// Whether it contains the transient Descriptor
Public static Boolean istransient (INT mod ){
Return (mod & Transient )! = 0;
}

// Whether the native descriptor is contained
Public static Boolean isnative (INT mod ){
Return (mod & Native )! = 0;
}

// Whether the interface descriptor is contained
Public static Boolean isinterface (INT mod ){
Return (mod & Interface )! = 0;
}

// Whether the abstract descriptor is contained
Public static Boolean isabstract (INT mod ){
Return (mod & abstract )! = 0;
}

// Whether the strict descriptor is contained
Public static Boolean isstrict (INT mod ){
Return (mod & strict )! = 0;
}

// Returns the string representation of this description.
Public static string tostring (INT mod ){
Stringbuffer sb = new stringbuffer ();
Int Len;

// Add different descriptors to stringbuffer
If (mod & Public )! = 0) sb. append ("public ");
If (mod & protected )! = 0) sb. append ("protected ");
If (mod & private )! = 0) sb. append ("private ");

/* Canonical order */
If (mod & abstract )! = 0) sb. append ("abstract ");
If (mod & Static )! = 0) sb. append ("static ");
If (mod & final )! = 0) sb. append ("final ");
If (mod & Transient )! = 0) sb. append ("transient ");
If (mod & volatile )! = 0) sb. append ("volatile ");
If (mod & synchronized )! = 0) sb. append ("synchronized ");
If (mod & Native )! = 0) sb. append ("native ");
If (mod & strict )! = 0) sb. append ("strictfp ");
If (mod & Interface )! = 0) sb. append ("interface ");

// If there is a defined descriptor, remove the last space.
If (LEN = sb. Length ()> 0)
Return sb. tostring (). substring (0, len-1 );
 
// No empty string is returned
Return "";
}

// Each specific location indicates a description type. If 1 is 0, it is not. If there is multiple 1, it indicates that there are multiple descriptors at the same time.
// It only uses 12 bits, which can be represented by short. It may be used for expansion consideration.

// The 1st-bit value of int type indicates public
Public static final int public = 0x00000001;

// 2nd bits indicate private
Public static final int private = 0x00000002;

// 3rd bits indicate protected
Public static final int protected = 0x00000004;

// 4th bits indicate static
Public static final int static = 0x00000008;

// 5th bits indicate final
Public static final int final = 0x00000010;

// 6th bits indicate synchronized (Mark synchronization method, synchronization block)
Public static final int synchronized = 0x00000020;

// 7th bits indicate volatile (indicating synchronization Security)
Public static final int volatile = 0x00000040;

// The 8th-bit value indicates the transient (indicating the fields not processed during persistence)
Public static final int transient = 0x00000080;

// 9th bits indicate nateive (local method)
Public static final int native = 0x00000100;

// 10th bits indicate Interface
Public static final int interface = 0x00000200;

// 11th indicates Abstract
Public static final int abstract = 0x00000400;

// The value of 12th indicates strict.
Public static final int strict = 0x00000800;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.