Java two varargs in one method

后端 未结 12 2170
小鲜肉
小鲜肉 2020-11-27 21:08

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 kn

12条回答
  •  粉色の甜心
    2020-11-27 22:02

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

     public void myMethod(List args1, List args2) {
       ...
     }
    
     -----------
    
     import static java.util.Arrays.asList;
     myMethod(asList(1,2,3), asList(4,5,6));
    

提交回复
热议问题