The getModifiers () method of java.lang.reflect.Field used to return the modifiers used for the field object as time of declaration, as an integer. The Modifier class should be used to decode the modifiers. Syntax:
public int getModifiers()
Parameters: This method accepts nothing. Return: This method returns the Java language modifiers for the underlying member. Below programs illustrate getModifiers () method: Program 1:
Java
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class GFG {
private static int number;
public static void main(String[] args)
throws NoSuchFieldException
{
Field field
= GFG. class
.getDeclaredField("number");
int modifiers
= field.getModifiers();
System.out.println(
Modifier
.toString(modifiers));
}
}
|
Program 2:
Java
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
public class GFG {
final static String value
= "Geeks";
public static void main(String[] args)
throws NoSuchFieldException
{
Field field
= GFG. class
.getDeclaredField("value");
int modifiers
= field.getModifiers();
System.out.println(
Modifier
.toString(modifiers));
}
}
|
References: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Field.html#getModifiers–
Feeling lost in the vast world of Backend Development? It's time for a change! Join our
Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule.
What We Offer:
- Comprehensive Course
- Expert Guidance for Efficient Learning
- Hands-on Experience with Real-world Projects
- Proven Track Record with 100,000+ Successful Geeks
Last Updated :
30 May, 2022
Like Article
Save Article