Thiago Medeiros wrote:... a list of Type Bird must accept a Bird.
Any help will be welcome.
The problem is, the compiler doesn't
know that it has a List of Birds. The
declaration of the variable "birds" says it's a List<? extends Bird>. As far as the compiler is concerned, it might be a List<Bird> or a List<Sparrow> or a List<RedFoxSparrow> or something else - it has no idea. When later code tries to add a Sparrow or Bird, the compiler can't guarantee that the List will accept that, because the List might be a type that can't accept Sparrow or Bird.
Generally, if you have a List<? extends Foo> you can take things
out of it, and the compiler will know that those things are
some type of Foo. But you can't put things
in to the list, because the compiler can't know what the ? in List<? extends Foo> actually represents. It could be something more specialized than the type you're trying to add.
<br />