Warning for generic varargs

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

I have declared the following method:

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


        
4条回答
  •  臣服心动
    2021-01-18 02:01

    For anyone landing here, the answers are a little old. Java 7 introduced the @Safevarargs annotation to address this:

    @SafeVarargs
    private void mockInvokeDBHandler(Map... rows) {
    

    From the javadoc:

    A programmer assertion that the body of the annotated method or constructor does not perform potentially unsafe operations on its varargs parameter. Applying this annotation to a method or constructor suppresses unchecked warnings about a non-reifiable variable arity (vararg) type and suppresses unchecked warnings about parameterized array creation at call sites.

提交回复
热议问题