First, we will finish off our variant TokenStream
programs from last time. (The link leads to the version we ended with.)
Specifically, we still need to write a
program that prints out each distinct token together with a count of
how many times it appears in the input. This will give us an
opportunity to use the Map
interface and
HashMap
class, as well as to see how the
Integer
wrapper class can be used with autoboxing and
autounboxing. Added after class: here is the version we ended up with.
Next, we can take a look at nested use of generic classes, for
example a Stack
of Set
s of
String
s.
Our third topic will be a look at the subtyping relationship with
generic classes. An Integer
is a kind of
Number
. Does that mean that a Set
of
Integer
s is a Set
of Number
s?
It sounds logical, but we need to be careful, among other reasons
because the Java notion of a Set
is different from how we
use that same word in mathematics. To see whether the proposed
subtyping makes sense, we'll have to think
about what our expectations are for a Set
of
Number
s and see whether a Set
of
Integer
s can meet all those expectations. On the other
hand, a Set
of Integer
s definitely is a
Collection
of Integer
s, from the fact that
Set
is a subtype of Collection
.
Finally, if time permits, we will consider the most basic use of wildcards, where the wildcard is not bounded. (Time didn't permit.)