I have method like this.
void method(int[] ...x){}
and i call method using method(new int[]{1,2,3,4});
it's ok. But compiler compile this 2d array type too.
method(new int[][]{new int[]{1,2,3},new int[]{4,5,6}});
I want know the reason. method has 1d array type reference. but compiler accept 2d array type.
The underlying type of a variadic method
function(Object... args)isfunction(Object[] args)
So an Object... is only a syntactic sugar for an Object[].
So the method void method(int[] ...x){} in your case having 1D array as parameter should be read as void method(int[][] x){} having 2D array as parameter
Hence it compiles and will give no runtime error also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With