Nov 19, 1997
Due: Nov 26
Stack
parameterized by T
, the type of object that
the stack contains. Stack
has two operations:
push
, which takes a single argument of type T
and
doesn't return anything; and pop
, which takes no arguments and
returns an object of type T
.
We also have an abstract type Sink
, again parameterized by
T
. Sink
has a single operation
push
, which takes a single argument of type T
and
doesn't return anything. (A Sink
is like a Stack
except that you can never get anything out of it.)
Finally, we have an abstract type Source
, parameterized by
T
. Source
has a single operation
pop
, which takes no arguments and returns an object of type
T
. (A Source
is like a Stack
except
that you can never put anything into it -- it just produces objects of
type T
. Where they come from is a mystery never fully
explained.)
Using the contravariant rule, what is the subtype relation between the
following pairs of types? (The answer to each question would be either
X
is a subtype of Y
, Y
is a subtype
of X
, or neither is a subtype of the other.)
Stack[Integer]
and Stack[Number]
Sink[Integer]
and Sink[Number]
Source[Integer]
and Source[Number]
Stack[Integer]
and Source[Number]
Stack[Number]
and Source[Integer]
Stack[Integer]
and Sink[Number]
Stack[Number]
and Sink[Integer]