Java变量可以在变量名中使用

Som*_*omk 1 java variables

我在我的代码中重复了几次这个小脚本.我知道我可以运行一个函数来轻松完成这个,但是我可以像PHP一样使用变量作为变量名.

   if (4val != null && 4val.length() > 0){
            Button 4 = new Button(this);
            4.setText(4val);
            4.setTextSize(20);
        }
Run Code Online (Sandbox Code Playgroud)

我希望能够做类似的事情

i=1;
while{i > 10}{
    $$i = value;
    //do stuff with $$i
    i++;
}
Run Code Online (Sandbox Code Playgroud)

这在Java中可行吗?

I82*_*uch 5

不.但你可以将按钮固定在一个数组中,然后迭代.

Button[] buttons = new Button[10];
// instantiate all the buttons
for (int i = 0; i < buttons.length; i++) {
   // update the button
}
Run Code Online (Sandbox Code Playgroud)