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

4.10

Subtyping

TYPES, VALUES, AND VARIABLES

first element may be a class or type variable, and only one type variable may appear in the bound) to preclude certain awkward situations coming into existence. However, capture conversion can lead to the creation of type variables whose bounds are more general (e.g., array types).

4.10 Subtyping

The subtype and supertype relations are binary relations on types.

The supertypes of a type are obtained by reflexive and transitive closure over the direct supertype relation, written S >1 T, which is defined by rules given later in this section. We write S :> T to indicate that the supertype relation holds between S and T.

S is a proper supertype of T, written S > T, if S :> T and S T.

The subtypes of a type T are all types U such that T is a supertype of U, and the null type. We write T <: S to indicate that that the subtype relation holds between types T and S.

T is a proper subtype of S, written T < S, if T <: S and S T.

T is a direct subtype of S, written T <1 S, if S >1 T.

Subtyping does not extend through parameterized types: T <: S does not imply that

C<T> <: C<S>.

4.10.1 Subtyping among Primitive Types

The following rules define the direct supertype relation among the primitive types:

double >1 float

float >1 long

long >1 int

int >1 char

int >1 short

short >1 byte

72

TYPES, VALUES, AND VARIABLES

Subtyping among Class and Interface Types 4.10.2

4.10.2 Subtyping among Class and Interface Types

Given a generic type declaration C<F1,...,Fn>, the direct supertypes of the parameterized type C<T1,...,Tn> are all of the following:

The direct superclasses of C.

The direct superinterfaces of C.

The type Object, if C is an interface type with no direct superinterfaces.

The raw type C.

The direct supertypes of the parameterized type C<T1,...,Tn>, where Ti (1 i n) is a type, are all of the following:

D<U1 θ,...,Uk θ>, where D<U1,...,Uk> is a direct supertype of C<T1,...,Tn> and θ is the substitution [F1:=T1,...,Fn:=Tn].

C<S1,...,Sn>, where Si contains Ti (1 i n) (§4.5.1).

The direct supertypes of the parameterized type C<R1,...,Rn>, where at least one of the Ri (1 i n) is a wildcard type argument, are the direct supertypes of C<X1,...,Xn> which is the result of applying capture conversion (§5.1.10) to C<R1,...,Rn>.

The direct supertypes of an intersection type T1 & ... & Tn are Ti (1 i n).

The direct supertypes of a type variable are the types listed in its bound.

A type variable is a direct supertype of its lower bound.

The direct supertypes of the null type are all reference types other than the null type itself.

4.10.3 Subtyping among Array Types

The following rules define the direct subtype relation among array types:

If S and T are both reference types, then S[] >1 T[] iff S >1 T.

Object >1 Object[]

Cloneable >1 Object[]

java.io.Serializable >1 Object[]

If P is a primitive type, then:

Object >1 P[]

Cloneable >1 P[]

73

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