Simplified Varargs Method Invocation in Java 7
In Java 7, you have the option to put a @SafeVarargs annotation to suppress the warning you get when compiling a method with a non-reifiable varargs parameter. Project Coin's proposal stipulates that the annotation should be used when the method ensures that only elements of the same type as the varargs parameter are stored in the varargs array. What would be an example of a non-safe method? For example, foo() is not safe, it may store non-T in the array, causing problem at [2] <T extends List<?>> void foo(T... args) { List<String>[] array2 = (List<String>[])args; array2[0] = a_list_of_string;