我对以下示例有问题:
public static void main(String[] args) {
// this works
int[] test1DArray = returnArray();
int[][] test2DArray = new int[][] {
// this does not work
new int[]= returnArray(),
// yet this does
new int[] {1, 2 ,3}
}
private static int[] returnArray() {
int[] a = {1, 2, 3};
return a;
}
我正在寻找一种方法来创建一个二维数组,并使第二维度成为从方法返回的数组。我不明白为什么它不能工作,因为我在Eclipse中得到的错误是:
赋值语句左侧必须是一个变量
据我所知,我正在创建一个新的int数组,并将返回的值分配给它。像这样立即填充第二维数组:
new int[] {1, 2 ,3}
这个功能运行良好,我想用从returnArray()
返回给我的数组做类似的事情。
非常感谢您的任何帮助。
p/