According to Java Generics FAQ
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeParameters.html#FAQ302
a type parameter cannot be forward-referenced in this way
<A extends B, B> // error
but it is ok to have
<A extends List<B>, B> // ok
These two examples are verified with the latest jdk 1.6.0_24.
My question is, where in the language spec this is specified, implied, or deductible(i.e. if it is untrue, other things can blow up). I can’t find it anywhere.
Update
In javac7, it is allowed. Intuitively, the order of type parameters doesn’t matter; the type system requires that there’s no cyclic dependencies among type variables: <A extends B, B extends A>. Previously, this can be guaranteed by forbidding forward reference. Apparently javac 7 is improved to relax the ordering, while detecting cycles regardless of ordering.
I’m not sure this is true. I looked over the Java Language Specification and in §6.3 there’s this discussion of the scopes of type parameters:
(My emphasis).
This suggests that in the declaration
that
Bis indeed in scope when writingA extends B.Furthermore, §4.4 of the JLS says, when referring to the bound on a type variable, that
Which suggests that not only is
Bin scope in<A extends B, B>, but that it’s a perfectly legal bound onA.Finally, to top things off, this code compiles in
javac:So I’m pretty sure that this is perfectly legal Java code and that the example you’ve linked to is either wrong or is referring to something else.
Hope this helps, and let me know if there’s a flaw in my reasoning!