java - 什么是 Java 中的综合字段?

标签 java compiler-construction field inner-classes synthetic

<分区>

谁能用通俗易懂的方式解释一下 Java 中合成字段的重要性。我记得在非静态内部类的上下文中阅读它,其中每个此类内部类实例都维护对封闭类的引用。为什么将此类引用/字段称为合成字段?

最佳答案

合成字段是编译器创建的字段,它将局部内部类链接到 block 的局部变量或引用类型参数。编译器综合某些隐藏字段和方法以实现名称范围。除非另有说明,否则这些字段是私有(private)的,或者它们最多在包范围内。您可以获得更多信息hereJLS

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/

相关文章:

编译器类型转换警告和错误

java - 封装 - 在同一个类中使用 setter/getter ?

java - 为什么 getAnnotation(Parsed.class).field() 返回 String[]?(它应该返回 String,因为它将输入作为 String)

c++ - QT Creator 没有链接

c++ - 函数中局部变量的生命周期是否一定等于该函数执行的生命周期?

django - 覆盖 django-allauth 表单字段

javascript - 将jsp变量传递给javascript

java - zip 命令在 Java 代码中未按预期工作

java - Restful Web 服务和 WSDL 之间有什么区别?

java - 如何在 spigot 1.16.4 中获取玩家的 ping