Warning for generic varargs

前端 未结 4 1984
暗喜
暗喜 2021-01-18 01:31

I have declared the following method:

private void mockInvokeDBHandler(Map... rows) {
    List> allRows         


        
4条回答
  •  感动是毒
    2021-01-18 02:00

    To pass the arguments to a varargs method the compiler will place the arguments into an array.

    The warning is to let you know that the compiler cannot guarantee that each of the elements in the array - each of the arguments to the varags method - is truly a Map.

    This is a bit of an annoying warning because there is no way you can work around this, other than to redefine the method signature to not use varargs. IMO it is safe to ignore as long as you are pretty sure of the actual run-time types of these arguments (which in this case, you are).

提交回复
热议问题