A variable arity parameter with an item type that is not available at run time can lead to littering of the heap and generate warnings about unchecked conversions at compile time.

What does the variable arity parameter mean?

    1 answer 1

    I think this is about varargs :

     void method(String ... strings){ for(String str: strings) System.out.println(str); } method("hello"); method("hello","world"); 

    And this warning is displayed when a parameter has a parameterized generic type.

     <T> void method(Iterator<T> iterators){ ,,, } 

    To understand why this is happening, you need to figure out how varargs work. The above method is converted to:

     <T> void method(Iterator<T>[]array){ ... } 

    And when called, the parameters are written to the created array:

     method(new Iterator[]{param1,param2}); 

    Note that when creating an array you cannot specify generic , i.e. in fact, an array of objects of type Iterator with the parameterized type Object . Because of this, problems may arise, which the compiler politely reports.

    You can remove a warning by annotating the method with @SuppressWarnings("unchecked") annotation, or starting with java 7 @SafeVarargs