Trying to wrap my head around this… hope it isn’t an Eclipse bug… that would be irritating…
interface A
{
void doStuff();
}
class B
{
Set<? extends A> doers;
public B()
{
doers = new HashSet<A>(); // do I have to use the wild card here too? It doesn't complain about the assignment.
}
void addA(A a)
{
// Eclipse complains about this: "The method add(capture-of ? extends A) in the type Set<capture-of ? extends A> is not applicable for the arguments (A)
doers.add(a);
}
void removeA(A a)
{
// But no complaint here!!
doers.remove(a);
}
void doStuff()
{
// and no complaint here
for(A a : doers)
{
a.doStuff();
}
}
}
)