what's the `4161` modifier mean in java.lang.reflect.Method

Adams.H :

i'm using java reflection to get method which are annotated with a specific Annotation . it returns two method , the one with modifier 4161 belongs to the interface . but i check the modifier specifications and can't find it anywhere ... help needed , tks :)

enter image description here

Robby Cornelissen :

The modifiers integer is basically a combination of integer flags that form a bit field. You can use the static Modifier.toString() method to get a textual representation. If you would use this method, it would tell you that 4161 stands for public volatile, and it would be wrong.

To break it down, the bit field represented by 4161 is composed of 3 integer flags: 1, 64 and 4096. Looking up these values in the Modifier Javadoc, it will tell you that 1 stands for public and 64 stands for volatile. Surprising, because methods cannot be declared as volatile, and what about 4096? It's not even in the list!

The answer can be found in the JVM specification, where we find that:

  • 4096 (0x1000) indicates a synthetic method, i.e. a method that is not present in the source code.
  • 64 (0x0040) not only represents the volatile access modifier, but can also be used to signify that a method is a bridge method, i.e. a method that is generated by the compiler.

The conclusion is then that a method with a modifiers value of 4161 is a public synthetic bridge method. This article provides a fairly comprehensive overview.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=86212&siteId=1