1

Where can I find a document to understand about JAVA/Reflection like below code ?

Field.class.getDeclaredField("modifiers")

What is getDeclaredField does?

What is a term "modifiers" do ?

I have seen reflection code in action from here

Community
  • 1
  • 1
Jongz Puangput
  • 5,527
  • 10
  • 58
  • 96

2 Answers2

4

From the javadoc which should be the first place you look when something is puzzling you.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
0

What is getDeclaredField does?

The method getDeclaredField(String name)

Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object.


What is a term "modifiers" do ?

"modifiers" here represents the name of the field to retrieve, as stated into the javadoc:

The name parameter is a String that specifies the simple name of the desired field.


To summarize Field.class.getDeclaredField("modifiers"), will get by reflection the field modifiers from the class Field.

 public final class Field extends AccessibleObject implements Member {
      ...
      private int                 modifiers; <-- this
      ...
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122