<分区>
谁能用通俗易懂的方式解释一下 Java 中合成字段的重要性。我记得在非静态内部类的上下文中阅读它,其中每个此类内部类实例都维护对封闭类的引用。为什么将此类引用/字段称为合成字段?
<分区>
谁能用通俗易懂的方式解释一下 Java 中合成字段的重要性。我记得在非静态内部类的上下文中阅读它,其中每个此类内部类实例都维护对封闭类的引用。为什么将此类引用/字段称为合成字段?
最佳答案
合成字段是编译器创建的字段,它将局部内部类链接到 block 的局部变量或引用类型参数。编译器综合某些隐藏字段和方法以实现名称范围。除非另有说明,否则这些字段是私有(private)的,或者它们最多在包范围内。您可以获得更多信息here在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..
关于java - 什么是 Java 中的综合字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17072899/