[英]synthetic static fields in java with type “java.lang.Class”
我在org.jfree.data.time.RegularTimePeriod类中看到了一些综合字段,却不知道它们的用途和用途。 我使用以下代码找出它们:
for (Field f : RegularTimePeriod.class.getDeclaredFields())
if (f.isSynthetic()) System.out.println(f);
它会给这些:
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
任何身体有什么主意吗? 我只是很好奇:)谢谢。
据我所知, synthetic members are only meant to be accessed by trusted code generated by the compiler, not haphazardly by reflection.
编译器综合某些隐藏字段和方法,以实现名称范围。 除非另有说明,否则这些字段是私有的,或者它们最多属于软件包范围。
指向最外面的封闭实例的合成字段称为this$0
。 下一个最外围的实例是this$1
,依此类推。 (在任何给定的内部类中,最多只有一个这样的字段是必需的。)一个包含常量v
的副本的合成字段称为val$v
。 这些字段是final
。
所有这些综合字段都是由构造函数参数初始化的,这些参数与它们初始化的字段具有相同的名称。 如果参数之一是最里面的封闭实例,则它是第一个。 所有这些构造函数参数都被认为是综合的。 如果编译器确定合成字段的值仅在构造函数的代码中使用,则它可以忽略字段本身,而仅使用参数来实现变量引用。
授予对私有成员或构造函数访问权限的非私有最终合成方法,其名称形式为access $ N,其中N为十进制数字。 此类访问协议的组织未指定。
我希望这有帮助。
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.