我知道这是一个有趣的问题。我想知道这是否可以完成?
Class foo {
public static void main(String [] args){
for (int i=0; i<5; i++)
//build string obji where i =0..5
//use the built string using stringbuilder and use the built string in this experssion
foo <built string> = new foo();
System.out.println(obj1.somemethod(i));
}
}
public somemethod(i){
return ("I am objet"+i)
}
}
最佳答案
没有。变量不是在执行时动态创建的。只需创建一个 Map<String, Foo>
相反,或者可能只是 Foo[]
.
不清楚为什么在这种情况下需要多个变量...但它只是伪代码...
关于java - 我们可以在作业的 LHS 上构建和使用字符串吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13825645/