Question: Consider a pluggable type system with two qualifiers over integers: 1. @NonZero, containing all integers i such that (i is not equal to 0) 2.
Consider a pluggable type system with two qualifiers over integers:
1. @NonZero, containing all integers i such that (i is not equal to 0)
2. @PossiblyZero, containing all integers including 0.
Our type checker should reject any division by a @PossiblyZero int as an error.
We have the following subtyping relationship between the qualifiers: @NonZero int @PossiblyZero int.The type qualifier for any non-zero constant is @NonZero. The type qualifier for the constant 0 is @PossiblyZero.Our default annotation is @PossiblyZero, so writing int is the same as writing @PossiblyZero int.
Indicate whether each of the following program excerpts should be accepted or rejected by the type checker.
1. @NonZero int x =3; Type checker should accept/reject. Briefly explain your answer.
2. @NonZero int x = 0; Type checker should accept/reject. Briefly explain your answer.
3. int x = 0; Type checker should accept/reject. Briefly explain your answer.
4.
static int m() { return 3; } static void n() { int x = 5 / m(); } Type checker should accept/reject. Briefly explain your answer.
5.
class C1 { @NonZero int m() { return 3; } } class C2 extends C1 { @Override @PossiblyZero int m() { return 0; } } Type checker should accept/reject. Briefly explain your answer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
