In the Java Language Specification, version 11, section 4.10.2, it reads, in part, while discussing direct supertypes of parameterized types:
Given a generic type declaration C<F₁,…,Fₙ> (n > 0), the direct supertypes of the parameterized type C<T₁,…,Tₙ>, where Tᵢ (1 ≤ i ≤ n) is a type, are all of the following:
(Then it lists a bunch of rules that apply to such parameterized types. These rules are mostly irrelevant for this question. They are relevant only in that they define direct supertypes for some cases of parameterized types.)
What "is a type" means can be found at the top of section 4.1:
There are two kinds of types in the Java programming language: primitive types (§4.2) and reference types (§4.3).
A reference type (we're not talking about primitives here, that's for sure) is simply a ClassOrInterfaceType
, a TypeVariable
or an ArrayType
.
Therefore a wildcard is not a kind of type.
(It is, in fact, a kind of TypeArgument
. You might think hazily and naïvely as I once did that a wildcard is a wonky kind of TypeVariable
, and hence a type, but you would be incorrect.)
So putting all this together, my reading of the relevant part of section 4.10.2 is:
- "the parameterized type C<T₁,…,Tₙ>, where Tᵢ (1 ≤ i ≤ n) is a type" has direct supertypes of various kinds…
- …but a parameterized type C<T₁,…,Tₙ>, where at least one Tₙ is a wildcard has no direct supertypes…
- …because the rules that are listed in this section do not apply wholly or partially to parameterized types containing at least one wildcard…
- …because a wildcard is not a type, so the "where Tᵢ (1 ≤ i ≤ n) is a type" condition is never met.
- …because the rules that are listed in this section do not apply wholly or partially to parameterized types containing at least one wildcard…
Is this a correct reading? In other words, is my deductive reasoning correct?
(It is perhaps worth noting in passing that there are types that can "contain" a parameterized type containing wildcards (as defined in section 4.5.1).)