我對Java有點新,我想知道是否有可能檢索已經用特定名稱定義的靜態變量的數量?例如:java - 定義了靜態變量計數
public static final String DB_CTRLDATA = "controldata";
public static final String DB_CTRLDATA_CELLADDR = DB_CTRLDATA + ".cell_addr";
public static final String DB_CTRLDATA_ID = DB_CTRLDATA + ".id";
public static final String DB_CTRLDATA_PRICT = DB_CTRLDATA + ".pri_count";
public static final String DB_CTRLDATA_RMODE = DB_CTRLDATA + ".rmode";
public static final String DB_CTRLDATA_TOD = DB_CTRLDATA + ".tod";
public static final String DB_DWELLDATA = "dwelldata";
public static final String DB_DWELLDATA_FILENAME = DB_DWELLDATA + ".filename";
public static final String DB_DWELLDATA_ID = DB_DWELLDATA + ".id";
public static final String DB_DWELLDATA_OFFSET = DB_DWELLDATA + ".offset";
public static final String DB_DWELLDATA_SIZE = DB_DWELLDATA + ".size";
public static final String DB_POSTPROC = "postproc";
public static final String DB_POSTPROC_ID = DB_POSTPROC + ".id";
public static final String DB_POSTPROC_PRESENT = DB_POSTPROC + ".present";
我想知道有多少個對象已經定義爲名稱DB_ *。我明白把所有這些放在一個數組中是一個解決方案。
謝謝!
你可以使用反射。你想用這些信息做什麼? –
另外,對象沒有名稱。田野呢。 –
答案是14 :-) –