Another way of constraining a generic is to use <T : ...>
syntax, where ...
is some type. This limits T
to being some sub-type of that type, rather than
an arbitrary class.
So, here, we constrain Transport
to transport a Thingy
. Since Animal
extends Thingy
, Van
can be a Transport<Animal>
. But we have no way to
create a Transport<String>
, for example, as String
does not extend
from the Thingy
base class.
You can learn more about this in:
Tags: