java方法变量需要是字符串,但需要数组
这是我的一段代码。我对insertPoint方法有问题。我需要命名一个数组。在insertPoint方法中,我给出了一个字符串变量,该变量给出了该方法的名称。但它不会使用“表达式的类型必须是数组类型,但它已解析为字符串”的名称。我尝试添加“Node name[]”,但它给了我一个错误,说“dublicate local variable name”。不知道如何解决这个问题
public class Node {
String name;
public void newArray(int number) {
this.name = "children" + number;
final Node name[] = new Node[4]; // Node's name should now be e.g. "children0"
insertPoint(this.x, this.y, size, this.name);
}
public void insertPoint(int x, int y, int size, String name) {
// Node name[]; // dublicate local variable name
if (this.x < c) {
if (name[0] == null) { // the type of the expression must be an array type but it resolved to string
name[0] = new Node(x, y, 0, 0, length);
} else {
newArray(0);
}
}
}
}
共 (0) 个答案