简体   繁体   English

类型为“ java.lang.Class”的java中的合成静态字段

[英]synthetic static fields in java with type “java.lang.Class”

I saw some synthetic fields in class org.jfree.data.time.RegularTimePeriod, and have no ideas what they are and are for. 我在org.jfree.data.time.RegularTimePeriod类中看到了一些综合字段,却不知道它们的用途和用途。 I use this code to find them out: 我使用以下代码找出它们:

for (Field f : RegularTimePeriod.class.getDeclaredFields())
    if (f.isSynthetic()) System.out.println(f);

And it will give these: 它会给这些:

static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$java$util$Date
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$java$util$TimeZone
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$org$jfree$data$time$Year
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$org$jfree$data$time$Quarter
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$org$jfree$data$time$Month
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$org$jfree$data$time$Day
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$org$jfree$data$time$Hour
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$org$jfree$data$time$Minute
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$org$jfree$data$time$Second
static java.lang.Class org.jfree.data.time.RegularTimePeriod.class$org$jfree$data$time$Millisecond

Any body have any idea? 任何身体有什么主意吗? I am just curious :) Thanks. 我只是很好奇:)谢谢。

As far as I know, synthetic members are only meant to be accessed by trusted code generated by the compiler, not haphazardly by reflection. 据我所知, synthetic members are only meant to be accessed by trusted code generated by the compiler, not haphazardly by reflection.

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. 除非另有说明,否则这些字段是私有的,或者它们最多属于软件包范围。

A synthetic field pointing to the outermost enclosing instance is named this$0 . 指向最外面的封闭实例的合成字段称为this$0 The next-outermost enclosing instance is this$1 , and so forth. 下一个最外围的实例是this$1 ,依此类推。 (At most one such field is necessary in any given inner class.) A synthetic field containing a copy of a constant v is named val$v . (在任何给定的内部类中,最多只有一个这样的字段是必需的。)一个包含常量v的副本的合成字段称为val$v These fields are final . 这些字段是final

All these synthetic fields are initialized by constructor parameters, which have the same names as the fields they initialize. 所有这些综合字段都是由构造函数参数初始化的,这些参数与它们初始化的字段具有相同的名称。 If one of the parameters is the innermost enclosing instance, it is the first. 如果参数之一是最里面的封闭实例,则它是第一个。 All such constructor parameters are deemed to be synthetic. 所有这些构造函数参数都被认为是综合的。 If the compiler determines that the synthetic field's value is used only in the code of the constructor, it may omit the field itself, and use only the parameter to implement variable references. 如果编译器确定合成字段的值仅在构造函数的代码中使用,则它可以忽略字段本身,而仅使用参数来实现变量引用。

A non-private final synthetic method which grants access to a private member or constructor has a name of the form access$N, where N is a decimal numeral. 授予对私有成员或构造函数访问权限的非私有最终合成方法,其名称形式为access $ N,其中N为十进制数字。 The organization of such access protocols is unspecified. 此类访问协议的组织未指定。

I hope this helps. 我希望这有帮助。

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM