From http://docs.oracle.com/javase/tutorial/extra/generics/wildcards.html
A list is an example of a limited template.? denotes an unknown type, as does the wildcard that we saw earlier. However, in this case, we know that this unknown type is actually a subtype of Shape. (Note: this may be the form itself or some subclass; it should not literally expand the form.) We say that Shape is the top border of the template.
There is, as usual, a price for the flexibility of using wildcards. This price is that it is now illegal to write in figures in the body of the method. For example, this is not valid:
public void addRectangle(List<? extends Shape> shapes) {
You must understand why the above code is not allowed. Is there a second parameter type for shape.add ()? extends Shape is an unknown subtype of Shape. Since we donβt know what it is, we donβt know if it is a supertype of Rectangle; it may or may not be such a supertype, so it is unsafe to pass a Rectangle.
In particular, speaking of your decision, you cannot cause a reaction with an object of type Elem , like with a type of Organic<? extends Elem> Organic<? extends Elem> , which you can legally assign compound = new Organic<ElemSubClass>() - and then react will cause a compilation error, since you cannot call it passing a superclass object.
manub source share