Exercise 15.x1: One can show the subtype relation on Java types by
drawing a diagram with arrows, where each arrow points from a subtype
to one of its supertypes. Arrows can be omitted that are implied by transitivity. As a simple example, if
the types under consideration are Integer
, Number
, and Object
,
one would draw an arrow pointing from Integer
to
Number
and a second arrow pointing from
Number
to Object
, but there would be no
need to show an arrow from Integer
directly to
Object
. Using this diagramming convention, show the
subtyping relation on List<?>
,
ArrayList<?>
,
List<Number>
, ArrayList<Number>
,
List<Integer>
, and ArrayList<Integer>
.
Exercise 17.x1: For each of the following two Java statements, indicate whether it is legal, and if so, explain under what circumstances each exception handler would execute. The first version is
try { System.in.read(); } catch(java.io.CharConversionException e2){ System.err.println("Caught a CharConversionException."); } catch(java.io.IOException e1){ System.err.println("Caught an IOException."); }
and the second version is
try { System.in.read(); } catch(java.io.IOException e1){ System.err.println("Caught an IOException."); } catch(java.io.CharConversionException e2){ System.err.println("Caught a CharConversionException."); }
Do exercise 18.6 on page 381.