I am using IntelliJ IDEA with javac on JDK 1.8. I have the following code:
class Test<T extends Throwable>
{
@SafeVarargs
final void varargsMethod( Collection<T>... varargs )
{
arrayMethod( varargs );
}
void arrayMethod( Collection<T>[] args )
{
}
}
IntelliJ IDEA does not highlight anything in the above code as a warning. However, when compiling, the following line appears in the "Make" tab of the "Messages" view:
Warning:(L, C) java: Varargs method could cause heap pollution from non-reifiable varargs parameter varargs
Note #1: I have already specified @SafeVarargs
.
Note #2: Warning:(L,C)
points to varargs
being passed as an argument to arrayMethod()
Assuming that I know what I am doing, and supposing that I am pretty sure that there will be no heap pollution or that I promise that I will not call this method in some funky way which might result in heap pollution, what do I need to do to suppress this warning message?
NOTE: There is a multitude of questions on stackoverflow regarding varargs methods, but it appears that there is none that addresses this specific problem. As a matter of fact, the entire interwebz appear to be rather poor in answers to this particular question.