Java Reference
In-Depth Information
4. Some languages, such as Ada, allow switch statements to have cases
labeled with a range of values. For example, with ranges, we might have
the following (using Java or C syntax):
switch (j) {
case 1..10,20,30..35 : option = 1; break;
case 11,13,15,21..29 : option = 2; break;
case 14,16,36..50
: option = 3; break;
}
How would you change the semantic analysis, reachability, and throws
visitors of Section 9.1.6 to allow case label ranges?
5. Consider the following program fragment:
...
while (a) {
if (b)
break;
else if (c)
a = update(a);
continue;
else return;
print(a,b,c)
}
...
Note that no matter which leg of the if is executed, the print statement
cannot be reached. This is quite possibly an error, and certainly deserves
a warning message.
Explain how the isReachable and terminatesNormally values set dur-
ing reachability analysis can be used to conclude that the above print
statement is unreachable.
6. Recall that in Java and C
amethod M is required to list all checked
exceptions that might be thrown to a caller of M .Intesting M it might
be helpful to verify that each exception listed in M 's ”throws list” really
can be thrown.
Explain how to use the techniques of Section 9.1.7 to verify that each
listed exception in a throws list of method M can potentially reach a
caller of M . Be sure to include exceptions thrown by methods called
from M (either directly or indirectly).
 
Search WWH ::




Custom Search