Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
java_language_specification_7.pdf
Скачиваний:
13
Добавлен:
21.03.2016
Размер:
3.11 Mб
Скачать

4.5.2

Members and Constructors of Parameterized Types

TYPES, VALUES, AND VARIABLES

by T1 under the reflexive and transitive closure of the following rules (where <: denotes subtyping (§4.10)):

? extends T <= ? extends S if T <: S

? super T <= ? super S if S <: T

T <= T

T <= ? extends T

T <= ? super T

The relationship of wildcards to established type theory is an interesting one, which we briefly allude to here. Wildcards are a restricted form of existential types. Given a generic type declaration G<T extends B>, G<?> is roughly analogous to Some X <: B. G<X>.

Historically, wildcards are a direct descendant of the work by Atsushi Igarashi and Mirko Viroli. Readers interested in a more comprehensive discussion should refer to On VarianceBased Subtyping for Parametric Types by Atsushi Igarashi and Mirko Viroli, in the

Proceedings of the 16th European Conference on Object Oriented Programming (ECOOP 2002). This work itself builds upon earlier work by Kresten Thorup and Mads Torgersen (Unifying Genericity, ECOOP 99), as well as a long tradition of work on declaration based variance that goes back to Pierre America's work on POOL (OOPSLA 89).

Wildcards differ in certain details from the constructs described in the aforementioned paper, in particular in the use of capture conversion (§5.1.10) rather than the close operation described by Igarashi and Viroli. For a formal account of wildcards, see Wild FJ by Mads Torgersen, Erik Ernst and Christian Plesner Hansen, in the 12th workshop on Foundations of Object Oriented Programming (FOOL 2005).

4.5.2 Members and Constructors of Parameterized Types

Let C be a generic class or interface declaration with type parameters A1,...,An, and let C<T1,...,Tn> be an invocation of C, where, for 1 i n, Ti are types (rather than wildcards). Then:

Let m be a member or constructor declaration (§8.2, §8.8.6) in C, whose type as declared is T.

The type of m in C<T1,...,Tn> is T[A1:=T1,...,An:=Tn].

Let m be a member or constructor declaration in D, where D is a class extended by C or an interface implemented by C. Let D<U1,...,Uk> be the supertype of C<T1,...,Tn> that corresponds to D.

The type of m in C<T1,...,Tn> is the type of m in D<U1,...,Uk>.

If any of the type arguments in the invocation of C are wildcards, then:

64

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]