Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java two varargs in one method

Is there any way in java, to create a method, which is expecting two different varargs? I know, with the same object kind it isn't possible because the compiler does'nt know where to start or to end. But why it also is'nt possible with to different Object types?

For example:

public void doSomething(String... s, int... i){     //...     //... } 

Is there any way to create method like this? Thank you!

like image 964
T_01 Avatar asked Jul 25 '13 20:07

T_01


1 Answers

Only one vararg, sorry. But using asList() makes it almost as convenient:

 public void myMethod(List<Integer> args1, List<Integer> args2) {    ...  }   -----------   import static java.util.Arrays.asList;  myMethod(asList(1,2,3), asList(4,5,6)); 
like image 71
rec Avatar answered Sep 20 '22 16:09

rec