Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of "static synthetic"?

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?

like image 517
Legend Avatar asked Mar 07 '11 17:03

Legend


People also ask

What is a synthetic class?

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.

What is a synthetic field in Java?

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.


2 Answers

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.

like image 172
ILMTitan Avatar answered Oct 07 '22 21:10

ILMTitan


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.

like image 25
Johan Sjöberg Avatar answered Oct 07 '22 21:10

Johan Sjöberg