Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
I am wondering whether the statements below are true
Upon looking at Angelika Langer's generics FAQ, she states in the following section:
Is List<Object> a supertype of List<String>?
No, different instantiations of the same generic type for different concrete type arguments have no type relationship.
So, my assumption would be that the answer would be false for each of the above statements.
But later down in the same section of the FAQ, there is this statement:
Compatibility between instantiations of the same generic type exist only among wildcard instantiations and concrete instantiations that belong to the family of instantiations that the wildcard instantiation denotes.
which indicates to me that there is a super-sub type relationship for wildcards.
So which is correct for the examples above?
Regarding the two quotes you posted, there is no contradiction. The first quote applies when both types are concrete, with no wildcards. List<Object> is neither a supertype nor subtype of List<String>. But the second quote applies where at least one of the types does use a wildcard.
You can see that I can assign a List<Number> to both List<? extends Number> and List<? super Number> because they are both supertypes of List<Number>. In order to do the reverse, I need to cast.
Note that this code will compile with warnings, but it's perfectly valid.