[英]Multi-Dimensional Array Issue Java
whenever i am passing two 1-d array as argument to a 2-d array it is working fine, but when i try to pass three 1-d arrays to a 3-d array argument method then it is giving error but same works fine when i pass three 1-d array to 2-d array. 每当我将两个1-d数组作为参数传递给2-d数组时,它都工作正常,但是当我尝试将三个1-d数组传递给3-d数组参数方法时,它给出了错误,但同样起作用当我将三个1维数组传递给2维数组时。
What is the reason behined this behaviour ? 这种行为背后的原因是什么?
Two 1-d array to a 2-d method:- 将两个一维数组转换为一个二维方法:-
int[] c=new int[] {4,50};
m1(new int[]{10,20},c);
public static void m1(int[]... a)]
Three 1-d array to a 3-d method :- , error - The method m1(int[][]...) in the type Asd is not applicable for the arguments (int[], int[], int[])
三个1-d数组到3-d方法:- ,错误
The method m1(int[][]...) in the type Asd is not applicable for the arguments (int[], int[], int[])
int[] b=new int[] {3,50};
int[] c=new int[] {4,50};
m1(new int[]{10,20},c,new int[] {4,50});
public static void m1(int[][]... a)
Three 1-d array to 2-d array:- 三个1维数组到2维数组:-
int[] c=new int[] {4,50};
m1(new int[]{10,20},c,new int[] {4,50});
}
public static void m1(int[]... a)
The ellipsis (...) is just an array. 省略号(...)只是一个数组。
int[]...a <=> int[][] a
int[][]...a <=> int[][][] a
in the second exemple the m1 method wait for a 3d array OR a list of 2d array, but you call it with a list of 1d array 在第二个示例中,m1方法等待3d数组或2d数组的列表,但是您使用1d数组的列表调用它
the good call is : 好的电话是:
m1(new int[][], new int[][] , ...)
and in the m1 method the a arg is of type int[][][] 在m1方法中,arg为int [] [] []类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.