Warning for generic varargs

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

I have declared the following method:

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


        
4条回答
  •  萌比男神i
    2021-01-18 01:54

    There's no way to avoid this warning, other than adding @SuppresWarning("unchecked") to the method :)

    Since you say it's a private method there's no "clients" in this case and you're in control of the method, so ignoring the warning seems reasonable.

    A few times when I've created methods taking parameterized types as a varargs parameter, I've created some overloads:

    void mockInvokeDBHandler(Map map1)
    void mockInvokeDBHandler(Map map1, Map map2)
    void mockInvokeDBHandler(Map map1, Map map2, Map... othermaps)
    

    That could avoid some of the warnings, depending on how many arguments are supplied.

提交回复
热议问题