Java two varargs in one method

后端 未结 12 2247
小鲜肉
小鲜肉 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:10

    You can do something like this, then you can cast and add additional logic inside that method.

    public void doSomething(Object... stringOrIntValues) {
        ...
        ...
    }
    

    And use this method like so:

    doSomething(stringValue1, stringValue2, intValue1, intValue2,         
        intValue3);
    

提交回复
热议问题