According to JLS§4.4:
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.
Consider the following snippet:
package TypeVarMembers;
class C {
public void mCPublic() {}
protected void mCProtected() {}
void mCPackage() {}
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.mCPackage(); // OK
//t.mCPrivate(); // Compile-time error
}
}
Here are some doubts that I have-:
- Erasure for method
test(T t)=>test(C t)?- if this is the case - then why are we dropping the additional types while computing Erasure?
- Implicit cast for the type
Tin methodtest(T t)=>(C & I)? - Theoretically is the erasure same as the implicit cast?