getmodifiers
类的类getModifiers()方法 (Class class getModifiers() method)
getModifiers() method is available in java.lang package.
getModifiers()方法在java.lang包中可用。
getModifiers() method is used to return the modifiers for this class or interfaces and the modifiers consist of JVM constants for the modifiers public, private, protected, final, static, abstract and interface and these modifiers should be decoded by the method getModifier() of Modifier class.
getModifiers()方法用于返回此类或接口的修饰符,并且修饰符由JVM常数组成,这些修饰符用于修饰符public,private,protected,final,static,abstract和interface,这些修饰符应由getModifier()方法解码修饰符类。
getModifiers() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
getModifiers()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
getModifiers() method does not throw an exception at the time of encoding a modifier.
在对修饰符进行编码时, getModifiers()方法不会引发异常。
Syntax:
句法:
public int getModifiers();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of this method is int, it returns an integer value representing the modifiers for the class or an interfaces.
此方法的返回类型为int ,它返回一个整数值,该整数值表示类或接口的修饰符。
Example:
例:
// Java program to demonstrate the example
// of int getModifiers () method of Class
import java.lang.reflect.*;
public class GetModifiersOfClass {
public static void main(String[] args) {
Thread th = new Thread();
// Get Class object of Thread
Class cl = th.getClass();
// It return the modifier of the class Thread
int modifiers = cl.getModifiers();
// Display Modifier in integer form
System.out.println("Before Conversion = " + modifiers);
// Convert Modifer from int to String by using toString()
String modifier = Modifier.toString(modifiers);
// Display Modifier in String form
System.out.print("After Conversion = " + modifier);
}
}
Output
输出量
Before Conversion = 1
After Conversion = public
翻译自: https://www.includehelp.com/java/class-class-getmodifiers-method-with-example.aspx
getmodifiers