Can someone explain in an easy to understand way the importance of synthetic fields in Java. I recall reading it in context of non static inner classes where each such inner class instance maintains a reference to the enclosing class. Why are such references/fields called synthetic fields?
-
http://stackoverflow.com/questions/5223268/what-is-the-meaning-of-static-synthetic and http://stackoverflow.com/questions/7767804/what-is-a-synthetic-back-reference-to-an-inner-class – assylias Jun 12 '13 at 18:41
1 Answers
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. These fields are private unless noted otherwise, or they are at most of package scope. You can get more information here and in JLS
A class member that does not appear in the source code must be marked using a Synthetic attribute, or else it must have its ACC_SYNTHETIC flag set. The only exceptions to this requirement are compiler-generated methods which are not considered implementation artifacts, namely the instance initialization method representing a default constructor of the Java programming language (§2.9), the class initialization method (§2.9), and the Enum.values() and Enum.valueOf() methods..

- 48,828
- 16
- 130
- 164
-
"A synthetic field is a compiler-created field that links a local inner class to a block's local variable or reference type parameter"...I do not understand the meaning of this line . A code example would help. – Geek Jun 12 '13 at 18:44
-
1You can look into this [blog](http://javapapers.com/core-java/java-synthetic-class-method-field/) for code example. – AllTooSir Jun 12 '13 at 18:47
-
1so if I am create a cloning thru reflection over fields, I must skip them right? – Aquarius Power Mar 03 '15 at 23:35
-