Java中的合成字段是什么?

编程入门 行业动态 更新时间:2024-10-11 19:13:36
本文介绍了Java中的合成字段是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以用一种易于理解的方式解释Java中合成字段的重要性.我记得在非静态内部类的上下文中阅读过它,其中每个这样的内部类实例都维护对封闭类的引用.为什么将这些引用/字段称为合成字段?

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?

推荐答案

合成字段是编译器创建的字段,该字段将本地内部类链接到块的本地变量或引用类型参数.编译器综合某些隐藏字段和方法,以实现名称范围.除非另有说明,否则这些字段是私有的,或者它们最多属于软件包范围.您可以获取更多信息此处并在 JLS

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

未出现在源代码中的类成员必须使用Synthetic属性进行标记,否则必须设置其ACC_SYNTHETIC标志.唯一的例外是编译器生成的方法,这些方法不被视为实现工件,即代表Java编程语言的默认构造函数的实例初始化方法(第2.9节),类初始化方法(第2.9节)和Enum. values()和Enum.valueOf()方法.

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中的合成字段是什么?

本文发布于:2023-11-25 21:17:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631380.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!