Java Reference
In-Depth Information
Furthermore, if there exists a supertype X of T , and a supertype Y of S , such that
both X and Y are provably distinct parameterized types (§ 4.5 ), and that the erasures
of X and Y are the same, a compile-time error occurs.
• If T is an interface type:
♦ If S is not a final class (§ 8.1.1 ), then, if there exists a supertype X of T , and a su-
pertype Y of S , such that both X and Y are provably distinct parameterized
types, and that the erasures of X and Y are the same, a compile-time error oc-
curs.
Otherwise, the cast is always legal at compile time (because even if S does not
implement T , a subclass of S might).
♦ If S is a final class (§ 8.1.1 ) , then S must implement T , or a compile-time error
occurs.
• If T is a type variable, then this algorithm is applied recursively, using the upper
bound of T in place of T .
• If T is an array type, then S must be the class Object , or a compile-time error occurs.
If S is an interface type:
• If T is an array type, then S must be the type java.io.Serializable or Cloneable (the only
interfaces implemented by arrays), or a compile-time error occurs.
• If T is a type that is not final 8.1.1 ) , then if there exists a supertype X of T , and a
supertype Y of S , such that both X and Y are provably distinct parameterized types,
and that the erasures of X and Y are the same, a compile-time error occurs.
Otherwise, the cast is always legal at compile time (because even if T does not im-
plement S , a subclass of T might).
• If T is a type that is final , then:
♦ If S is not a parameterized type or a raw type, then T must implement S , or a
compile-time error occurs.
♦ Otherwise, S is either a parameterized type that is an invocation of some gener-
ic type declaration G , or a raw type corresponding to a generic type declaration
G . Then there must exist a supertype X of T , such that X is an invocation of G ,
or a compile-time error occurs.
Furthermore, if S and X are provably distinct parameterized types then a
compile-time error occurs.
If S is a type variable, then this algorithm is applied recursively, using the upper bound of
S in place of S .
Search WWH ::




Custom Search