Java Generic Collection of Generic Type with Bounded Wildcard
bounded-wildcard, collections, generics, java
Solution
When assigning to a variable (`Set<T>`) with a non-wildcard generic type `T`, the object being assigned must have exactly `T` as its generic type (including all generic type parameters of `T`, wildcard and non-wildcard). In your case `T` is `Cage<Lion>`, which is not the same type as `Cage<? extends Animal>`.
What you can do, because `Cage<Lion>` is assignable to `Cage<? extends Animal>`, is use the wildcard type:
Set<? extends Cage<? extends Animal>> a = new Set<Cage<Lion>>();
Problem
Please help me with this: If `Lion IS-A Animal` and given `Cage<T>`: ``` Cage<? extends Animal> c = new Cage<Lion>(); // ok, ``` but ``` Set<Cage<? extends Animal>> cc = new HashSet<Cage<Lion>>(); // not ok ``` What I don't see here?