As janoh.janoh mentioned above, varargs in Java is just syntactic sugar for arrays plus implicit array creation on the calling site. So
List<List<String>> combinations = Utils.createCombinations(cocNumbers, vatNumbers, ibans);
in fact
List<List<String>> combinations = Utils.createCombinations(new List<String>[]{cocNumbers, vatNumbers, ibans});
But, as you know, new List<String>[] not allowed in Java for reasons that were raised in many other issues, but mainly due to the fact that arrays know their type of component at runtime and check at runtime added whether the elements are in accordance with their component type, but this check is not possible for parameterized types.
Anyway, instead of a failure, the compiler creates an array anyway. He does something similar to this:
List<List<String>> combinations = Utils.createCombinations((List<String>[])new List<?>[]{cocNumbers, vatNumbers, ibans});
This is potentially dangerous, but not necessarily unsafe. Most varargs methods simply iterate over varargs elements and read them. In this case, it does not care about the runtime type of the array. This applies to your method. Since you are on Java 7, you must add the @SafeVarargs annotation to your method and you will no longer receive this warning. This annotation basically says that this method only cares about the types of elements, and not about the type of the array.
However, there are some varargs methods that use an array runtime type. In this case, it is potentially dangerous. That is why there is a warning.
newacct Jan 15 '14 at 23:42 on 2014-01-15 23:42
source share