I am using IntelliJ IDEA with javac on JDK 1.8. I have the following code:
class Test
{
@SafeVarargs
final void varargsMe
Assuming that I know what I am doing
I refuse to assume this since this seems incredibly wrong.
The situation you're running into here is that, because generics are not reifiable, you're declaring a generic array, which is generally frowned upon. Generics and arrays don't mix very well, given that an array is covariant (String[]
is an Object[]
in the same way that a String
is an Object
), whereas generics are invariant (List
is not a List
, even though a String
is an Object
).
If you want a collection of collections...just pass one. It's safer than mingling arrays and generics.
final void varargsMethod(Collection<> collections) { }