Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 787
Adams.H Avatar asked Nov 30 '25 04:11

Adams.H


1 Answers

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.

like image 102
Robby Cornelissen Avatar answered Dec 02 '25 16:12

Robby Cornelissen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!