java中类型为“的合成静态字段”;java.lang.Class”的;
我在org.jfree.data.time.RegularTimePeriod类中看到了一些合成字段,不知道它们是什么,用于什么。我使用此代码查找它们:java中类型为“的合成静态字段”;java.lang.Class”的;,java,reflection,synthetic,Java,Reflection,Synthetic,我在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.RegularTimePeri
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
有人知道吗?我只是好奇:)谢谢。据我所知,
合成成员只能由编译器生成的可信代码访问,而不是随意地通过反射。
编译器综合某些隐藏字段和方法以实现名称的作用域。除非另有说明,否则这些字段是私有的,或者它们最多在包范围内
指向最外层封闭实例的合成字段名为this$0
。下一个最外层的封闭实例是这个$1
,依此类推。(在任何给定的内部类中,最多需要一个这样的字段。)包含常量v
副本的合成字段被命名为val$v
。这些字段是final
所有这些合成字段都由构造函数参数初始化,这些参数与它们初始化的字段具有相同的名称。如果其中一个参数是最里面的封闭实例,则它是第一个。所有此类构造参数均视为合成参数。如果编译器确定合成字段的值仅用于构造函数的代码中,它可能会忽略字段本身,而仅使用参数来实现变量引用
授予私有成员或构造函数访问权限的非私有最终合成方法的名称形式为access$N,其中N是十进制数字。这类访问协议的组织尚未明确
我希望这有帮助
干杯你想要什么?另请参见:引用是一种很好的做法。