How to declare method's return type the as return type of last lambda in array passed to the method

前端 未结 3 598
清酒与你
清酒与你 2021-01-05 19:51

I ask for something which I see impossible and I\'ll delete question if it is.

I have got method:

public Object convertBy(Function... functions) {
}
         


        
3条回答
  •  难免孤独
    2021-01-05 19:58

    You have to change the method signature and inline the last vararg value as a separate parameter.

    If you have this parameter as the last one, then you won't be able a use vararg parameter, as it has always to be last one and must be represented as an array in case it's not the last one:

    public  R convertBy(Function[] functions, Function special) { }
    

    If you, however, insist to use varargs, then you can move the "special" Function as first parameter:

    public  R convertBy(Function special, Function... functions) { }
    

提交回复
热议问题