Title: Generics
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER > Section: Learning Units - Bb

Presentations and Videos

- Generics lecture video (Time: 30:00)
- Generics document
- Generics was added to Java in order to allow Java classes to be more flexible. Generics is similar to C++ templates.
  - The basic idea is to have 1 ormore data types be parameters for a given class. For example, a sort routine could sort an array of any kind of class because the type of the class sorted would be a parameter. Most of the data structure classes in Java make use of generics. See the textbook examples: Sample.java, Pair.java, UnorderedPair.java, TwoTypePair.java, and Pair2.java.
  - AnimalCollection.java - This is a rework of the cps161 assignment where we had Animal, Cow, Horse, Snake and Zoo classes. Note that by using generics we can control the nature of the AnimalCollection ... dairy, snakePit, zoo
  - The MyArrayList.java class from the previous lecture which was based on a list of Objects is updated to use generics.