如何将变量重命名为数组的一部分?

时间:2021-01-16 00:53:00

I've written my code to include a variable called rectangleX, but now I'd like to have multiple similar variables, so I want to rename the variable to rectangleX[0]. However, when I go to refactor, then rename, I get the error 'Inserted identifier is not valid'. How can I get around this?

我编写了我的代码以包含一个名为rectangleX的变量,但现在我想要有多个类似的变量,所以我想将变量重命名为rectangleX [0]。但是,当我去重构,然后重命名时,我得到错误'插入的标识符无效'。我怎么能绕过这个?

1 个解决方案

#1


0  

It looks like you're trying to change a single variable into an array. I'd suggest separating it out, or simply add your rectagleX variables directly to the List.

看起来您正在尝试将单个变量更改为数组。我建议把它分开,或者直接将你的rectagleX变量直接添加到List中。

List<String> rectangleList= new ArrayList<String>();
rectangleList.add(rectangleXVar1);
rectangleList.add(rectangleXVar2);
rectangleList.add(rectangleXVar3);
rectangleList.add(rectangleXVar4);

for(int i=0;i<rectangleList.length;i++) {
    System.out.println(rectangleList[i]);
}

#1


0  

It looks like you're trying to change a single variable into an array. I'd suggest separating it out, or simply add your rectagleX variables directly to the List.

看起来您正在尝试将单个变量更改为数组。我建议把它分开,或者直接将你的rectagleX变量直接添加到List中。

List<String> rectangleList= new ArrayList<String>();
rectangleList.add(rectangleXVar1);
rectangleList.add(rectangleXVar2);
rectangleList.add(rectangleXVar3);
rectangleList.add(rectangleXVar4);

for(int i=0;i<rectangleList.length;i++) {
    System.out.println(rectangleList[i]);
}