私はString
で値を取得することができ、このクラスにStringを介してクラスのObjectから値を取得する方法はありますか?
public class Register{
String name;
int value;
int lockedValue = 0;
Registro(String name){ this.name = name; }
public int getValue(){ return value; }
// rest of get and set methods
}
とメインクラス
public class Simulator{
static Register $t0, $t1, $t2;
public static void main(String[] args) throws IOException {
$t1 = new Register("$t1");
$t1.setValue(15);
$t2 = new Register("$t2");
$t2.setValue(20);
// here i can get values by $t1.getValue()
}
}
を持っている、などのように:?あなたがしたいようだ
String nameRegister = "$t1";
int fetchValue = nameRegister.getValue();
あなたは '使用することができますMap 'を呼び出します。 –
@ElliottFrischあなたが答えをしなければ、私はそれをアップボートしません。 –
ヒント:決して**変数名に$文字を使用しないでください。 $は(生成された*コードのみのため)(慣例により)! – GhostCat