だから私は次のものを持っています:
String string = "camera_icon"
そして私が持っている別の場所に:
Object camera_icon = new Object();
私はそれを次のように参照します:
do.some.stuff(camera_icon);
次のように入力する方法はありますか。
do.some.stuff(文字列);
そしてそれを機能させます。
リフレクションの使用:
class Main
{
YourObject cameraIcon = new YourObject();
public void someMethod() throws Exception
{
Field field = getClass().getDeclaredField("cameraIcon");
YourObject object = (YourObject)field.get(this);
}
}
私の知る限り、リフレクションを使用してローカル変数を取得することはできません。
public void someMethod() throws Exception
{
YourObject cameraIcon = new YourObject();
// can't get cameraIcon from "cameraIcon" here
}