static void m(int ...x,double ...y){}
I'm try to use this method. But it compile error.I want to know the reason.
int x[]=new int[2];
double y[]=new double[2];
I make two arrays like this and i want parse them to method m.
m(x,y); like this.
static void m(int ...x,double ...y){}
I'm try to use this method. But it compile error.I want to know the reason.
int x[]=new int[2];
double y[]=new double[2];
I make two arrays like this and i want parse them to method m.
m(x,y); like this.
You cannot have double varargs like void m(int ...x,double ...y){}
.
Instead you can have void m(int[] x, double[] y){}
.
Reading from official documentation:
Varargs can be used only in the final argument position.
You can not have double varargs but the key question is "why this is not possible?" because the restriction does not come from Java itself. For example consider this two cases:
someMehod(Shape ...shape, Square ...square)
-> you don't know where the Shape
args stop or where Square
args begin.Square
extends Shape
-> the Shape
class can exist in ...shape
and ...square
args due the polymorphism and this is quite confusing.