I am looking at some disassembled code obtained from Java bytecode. I see some declaration as follows:
.method static synthetic access$0()Lcom/package/Sample;
I am not able to figure out what the synthetic
or access$0
mean. Can someone please help me understand this part?
A synthetic class is a . class file generated by Java Compiler and it does not exist in the source code. Example usage of synthetic class: Anonymous inner class.
A synthetic field is a compiler-created field that links a local inner class to a block's local variable or reference type parameter. The compiler synthesizes certain hidden fields and methods in order to implement the scoping of names.
In the java language, inner classes can access private members of their enclosing class. However, in Java bytecode, the concept of inner classes does not exist, and the private members are not accessible. To work around this, the compiler creates synthetic accessor methods in the outer class. I believe that is what you are seeing here. access$0
is simply the name of the method. I'm not sure what, if anything the synthetic
does. It may just hide the method from other compilers to ensure encapsulation.
Synthetic field, (2)
A compiler-created field that links a local inner class to a block's local variable or reference type parameter.
See also The JavaTM Virtual Machine Specification (§4.7.6)
or Synthetic Class in Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With