我正在尝试创建一个看起来像object1 [] .object2 []的对象数组。但是,我的代码似乎不起作用,所以我的代码在哪里出错?
public class Program
{
public static void main(String[] args) {
int evolve = 1;
int rows = 2;
Evolution[] a = new Evolution[evolve];
for(int i=0; i<evolve; i++){
a[i] = new Evolution();
Evolution.Node[] b = a[i].new Node[rows];
}
}
}
public class Evolution{
double fitness;
public class Node{
double value = 900; //900 was a test value
}
public class Synapsis extends Node{
double weight;
double input;
double output;
}
}
答案 0 :(得分:0)
您将内部类实例化的语法与数组实例化混淆。您的数组创建应如下所示:
Evolution.Node[] b = new Evolution.Node[rows];
如果你想填充数组,那么你需要这样的东西:
for (int j = 0; j < rows; j++) {
b[j] = a[i].new Node();
}