Some classes employ "generics". This is a way for you to indicate some data type on which those classes operate.
Here, we are declaring that critters
is not just an ArrayList
, but it
is an ArrayList
that can only hold Animal
objects. The <Animal>
syntax constrains this particular ArrayList
to only hold Animal
objects.
If you try adding an object of some other type, you will fail with a compile
error.
You can learn more about this in:
Tags: