Java Reference
In-Depth Information
A type variable must not at the same time be a subtype of two interface types which are
different parameterizations of the same generic interface, or a compile-time error occurs.
The order of types in a bound is only significant in that the erasure of a type variable is
determined by the first type in its bound, and that a class type or type variable may only
appear in the first position.
The members of a type variable X with bound T & I 1 & ... & I n are the members of the
intersection type (ยง 4.9 ) T & I 1 & ... & I n appearing at the point where the type variable is
declared.
Example 4.4-1. Members of a Type Variable
Click here to view code image
package TypeVarMembers;
class C {
public void mCPublic() {}
protected void mCProtected() {}
void mCDefault() {}
private void mCPrivate() {}
}
interface I {
void mI();
}
class CT extends C implements I {
public void mI() {}
}
class Test {
<T extends C & I> void test(T t) {
t.mI(); // OK
t.mCPublic(); // OK
t.mCProtected(); // OK
t.mCDefault();
// OK
t.mCPrivate();
// Compile-time error
}
}
The type variable T has the same members as the intersection type C & I , which in turn
has the same members as the empty class CT , defined in the same scope with equival-
ent supertypes. The members of an interface are always public , and therefore always
inherited (unless overridden). Hence mI is a member of CT and of T . Among the mem-
bers of C , all but mCPrivate are inherited by CT , and are therefore members of both CT
and T .
Search WWH ::




Custom Search