Parametric Polymorphism - Generic Java

Problems: Solution:

Covariant return types: can return a subtype of what is declared in your super. Example:

figure here

Is this okay? Why does it work? Because... A dog IS AN animal.

Parametric Polymorphism aka Generics

Definition: parametric polymorphism = polymorphic on a type which is parameter.

Ways to think of it:

What does this mean about classes and types? Is a list of dogs a list of animals?

figure of UML of generics

No because what if you put a cat in my list of dogs?

Syntax of GJ for generic classes and also limitations.

Now we have a list of data and we know the type, what about the accept method? It doesn't know what type the visitor wants, put it doesn't care. Its contract is that is won't touch what you pass along. Like wise with the return value.

Introduce generic methods Show the singleton hack. This doesn't occur in LRStruct nodes but it does happen in LRStruct state.
Wrap up, discuss exceptions what we want and what we have. Mention special cases and syntax in GJ.

jwalker@cs.oberlin.edu