簡體   English   中英

類型為“ java.lang.Class”的java中的合成靜態字段

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM