java warning: Varargs method could cause heap pollution from non-reifiable varargs parameter

前端 未结 5 1638
灰色年华
灰色年华 2021-01-17 17:32

I am using IntelliJ IDEA with javac on JDK 1.8. I have the following code:

class Test
{
    @SafeVarargs
    final void varargsMe         


        
5条回答
  •  北海茫月
    2021-01-17 18:24

    An additional (and quite superfluous-looking) @SuppressWarnings( "varargs" ) is needed to suppress the warning, as follows:

    @SafeVarargs
    @SuppressWarnings( "varargs" )
    final void varargsMethod( Collection... varargs )
    {
        arrayMethod( varargs );
    }
    

提交回复
热议问题