0

如果我有这样的课程Base

public static Tab thisTab = new TabClass(5200, "thisItem");
public final static Item thisItem = new SomeClass(par1, par2);

TabClass课堂上,我希望能够从中访问一些信息thisItem,但不TabClass知道thisItem

public TabClass(int par1, String par2) {
    int num;
    Base.(Here is where i need the item that par2 is the name of).ID = num;
}

在查找 ID 的值时,我如何以某种方式获得par2表示实际可用的字段?

4

1 回答 1

0

尝试java反射方法..

Item item = new Item();
Field field = Item.class.getDeclaredField(par2);
field.set(item, new Item(234));

你的 Item 类有构造函数

public Item(int ID){
    this.ID = ID;
}
于 2013-11-14T04:55:08.880 回答