如何使用以下 System.out.println
打印欢迎信息。
生成后会给出ac
。但是我应该如何让它成为 welcome
(即 ac 值而不是 "ac"
)
public class BrowserSample {
public static void main(String[] args) {
String generated = "ac";
String ac = "welcome";
System.out.println("value from generated is = " + generated);
}
}
最佳答案
ok 经过简短的实验这里是你想要的解决方案
String generated = "ac";
String ac = "welcome"; // declare as member of class
String s = (String) getClass().getDeclaredField(generated).get(this);
s 将包含 welcome
关于java - 如何从其他生成的等效字符串中获取字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16603620/