首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >java中合成属性的格式是什么?

java中合成属性的格式是什么?
EN

Stack Overflow用户
提问于 2013-08-31 11:38:01
回答 1查看 345关注 0票数 4

在阅读oracle教程(反思)字段修饰符时,我提到了合成属性( field )这个术语:

请注意,即使未在原始代码中声明某些字段,也会报告它们。这是因为编译器将生成运行时需要的一些合成字段。为了测试一个字段是否是合成的,该示例调用Field.isSynthetic()。

这些合成字段的结构或格式或一般的合成属性是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-31 13:05:58

这就是我在JVM SE7规范中发现的

代码语言:javascript
复制
The Synthetic attribute is a fixed-length attribute in the attributes
table of a ClassFile, field_info, or method_info structure (§4.1,
§4.5, §4.6). 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.


The Synthetic attribute was introduced in JDK release 1.1 to support 
nested classes and interfaces.

The Synthetic attribute has the following format:

Synthetic_attribute {
    u2 attribute_name_index;
    u4 attribute_length;
}

The items of the Synthetic_attribute structure are as follows:

attribute_name_index

    The value of the attribute_name_index item must be a valid index into
    the constant_pool table. The constant_pool entry at that index must be
    a CONSTANT_Utf8_info (§4.4.7) structure representing the string "Synthetic".

attribute_length

    The value of the attribute_length item is zero.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18547723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档