Home  >  Article  >  Java  >  How to get field modifiers in java class

How to get field modifiers in java class

WBOY
WBOYforward
2023-05-16 12:31:061003browse

1. Description

The fields in the class have many modifiers, such as public, private, transient, etc. Java provides an API to get the modifier of a class, but what you get is an int type. Fortunately, Java provides modifier classes to determine the resulting integer.

2. Example

public class Main {
    public static int a = 1;
    public static void main(String[] args) throws NoSuchFieldException {
        Class c = Main.class;
        Field field = c.getField("a");
        System.out.println(Modifier.isPublic(field.getModifiers()));
        System.out.println(Modifier.isStatic(field.getModifiers()));
    }
}

What are the advantages of Java

1. Simple. As long as you understand the basic concepts, you can write programs suitable for various applications. Applications in this situation;

2. Object-oriented;

3. Distribution, Java is a network-oriented language;

4. Robustness, java provides automatic Garbage collection is used for memory management to prevent programmers from making errors when managing memory;

5. Security, Java used in network and distributed environments must prevent virus intrusion;

6. Architecture neutrality, as long as the Java runtime system is installed, it can run on any processor;

7. Portability, Java can be easily transplanted to different machines on the network;

8. Interpretation and execution. The Java interpreter directly interprets and executes the Java bytecode.

The above is the detailed content of How to get field modifiers in java class. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete