1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
package defaulting.lowerbound;
// This test's sole purpose is to check that implicit and explicit LOWER_BOUND defaulting work as
// expected.
import testlib.defaulting.LowerBoundQual.*;
class MyArrayList<MAL extends String> {}
class MyExplicitArray<MEA extends String> {}
public class LowerBoundDefaulting {
// IMP1 is of type IMP1 [extends @LbTop super @LbImplicit]
public <IMP1 extends String> void implicitsTypeVar() {
// should fail because @LbImplicit is below @LbTop
@LbTop MyArrayList<@LbTop ? extends @LbTop String> itLowerBoundIncompatible =
// :: error: (assignment.type.incompatible)
new MyArrayList<IMP1>();
// :: error: (type.argument.type.incompatible)
@LbTop MyArrayList<@LbExplicit ? extends @LbTop String> itLowerBoundStillIncompatible =
// :: error: (assignment.type.incompatible)
new MyArrayList<IMP1>();
@LbTop MyArrayList<@LbImplicit ? extends @LbTop String> itLowerBoundCompatible =
new MyArrayList<IMP1>();
}
public void implicitsWildcard(MyArrayList<?> myArrayList) {
// should fail because @LbImplicit is below @LbTop
// :: error: (assignment.type.incompatible)
@LbTop MyArrayList<@LbTop ? extends @LbTop String> iwLowerBoundIncompatible = myArrayList;
// :: error: (assignment.type.incompatible) :: error: (type.argument.type.incompatible)
@LbTop MyArrayList<@LbExplicit ? extends @LbTop String> iwLowerBoundCompatible = myArrayList;
@LbTop MyArrayList<@LbImplicit ? extends @LbTop String> iwLowerBoundStillCompatible = myArrayList;
}
public void implicitExtendBoundedWildcard(MyArrayList<? extends String> iebList) {
// should fail because @LbImplicit is below @LbTop
// :: error: (assignment.type.incompatible)
@LbTop MyArrayList<@LbTop ? extends @LbTop String> iebLowerBoundIncompatible = iebList;
// :: error: (assignment.type.incompatible) :: error: (type.argument.type.incompatible)
@LbTop MyArrayList<@LbExplicit ? extends @LbTop String> iebLowerBoundStillIncompatible = iebList;
@LbTop MyArrayList<@LbImplicit ? extends @LbTop String> iebLowerBoundCompatible = iebList;
}
// :: error: (type.argument.type.incompatible)
public void explicitLowerBoundedWildcard(MyArrayList<? super String> elbList) {
// should fail because @LbExplicit is below @LbTop
// :: error: (assignment.type.incompatible)
@LbTop MyArrayList<@LbTop ? super @LbTop String> iebLowerBoundIncompatible = elbList;
// :: error: (type.argument.type.incompatible)
@LbTop MyArrayList<@LbTop ? super @LbExplicit String> iebLowerBoundStillIncompatible = elbList;
// :: error: (assignment.type.incompatible)
@LbTop MyArrayList<@LbTop ? super @LbImplicit String> iebLowerBoundCompatible = elbList;
}
}
|