-2
因此,在一個類(ImportantClass123)我有這樣的:公共領域 - 你怎麼能得到一個公共領域顯示其名稱(字符串)
public AnotherImportantClass aReallyImportantClass;
如何退還
AnotherImportantClass
通過什麼樣的命名爲領域的知識:
aReallyImportantClass
喜歡的東西
ImportantClass123.getFieldWithName("aReallyImportantClass");
?
我該如何編寫getFieldWithName?它的返回類型是什麼?類?
你需要像反射API,[閱讀](http://stackoverflow.com/questions/160970/如何做 - 我 - invoke - 一個Java方法 - 當給定的方法名字作爲字符串) –
https://docs.oracle.com/javase/tutorial/reflect/member/fieldValues .html – shmosel
@shmosel OP正在尋找字段的類型,而不是數值。令人驚訝的是,我找不到重複的。 –