Compiler bug? "reference to addAll is ambiguous"
I've got a piece of code which compiles fine in Eclipse, but seems to have
problem with Sun's compiler. I'm not sure of the exact version of Sun's
compiler being used, the error was reported to me by a coworker. Here's
the error message:
<errorMessage>
Rewriting\src\java\gov\sc\eip\report\birt\ChangesRowGenerator.java:116:
reference to addAll is ambiguous, both method
addAll(java.util.Collection<? extends E>) in
java.util.Collection<capture#420 of ? super
gov.sc.eip.report.birt.items.ChangeRow> and method
addAll(java.util.Collection<? extends E>) in java.util.List<capture#420 of
? super gov.sc.eip.report.birt.items.ChangeRow> match
</errorMessage>
I didn't post an SSCCE because (1) I'm not sure I'm allowed to and (2)
because I think the error message is sufficient to demonstrate that there
may be a bug... either in the compiler, or in my understanding of
overwriting.
It seems to me that the error message is saying that it cannot determine,
from my code, whether the .addAll() which I am calling refers to the
..addAll in java.util.Collection or the .addAll() in java.util.List. But
doesn't the .addAll() in java.util.List overwrite the .addAll() in
java.utilCollection, so that the "List-version" always be the one invoked?
And anyway, aren't these both interfaces, and thus provide zero
implementation, and thus it doesn't really matter which of these two
methods are being called, since they will eventually point to the exact
same implementation depending on what underlying concrete type is
involved?
In case it's relevant, I'll include the statement where the error is
generated:
<veryShortSnippet>
rows.addAll(getRowForGenericChange(changeSet.getCountyChange(),
CommonFieldNamesEnum.COUNTY.getCode()));
</veryShortSnippet>
"rows" is a parameter past into the method of type "List<? super
ChangeRow>". As you can see, I'm not doing any weird casting to bypass the
overwriting (e.g. I'm not doing something like
"((Collection)rows).addAll(whatever)", which in my opinion should work
even if I did do that anyway).
- Oliver