Reading the Java online tutorial I haven\'t understand anything about wildcard capture. For example:
import java.util.List;
public class WildcardErro
I guess your misunderstanding of the restriction comes from substitution of ?
for any type
, Object
or something like that in your mind. But that assumption is not correct, ?
in fact means unknown type
. So in the following line
fooz.set(0, foo);
you're trying to assign the variable of some type to the variable of unknown type (since the function signature is like void set(int, ?)
), which can never be possible, whatever the type of foo
would be. In your case the type of foo is Object
and you cannot assign it to a variable of some unknown type, which in fact may be Foo
, Bar
or any other.