Close
Register
Close Window

Show Source |    | About   «  2.3. Java Arrays   ::   Contents   ::   2.5. Lab 2 Polymorphism  »

2.4. Generics Intro

2.4.1. Objectives

  • Declare variables and instantiate objects that are generic types and take a type parameter

  • Trace code that demonstrates the use of both generics and inheritance

  • Design and write a generic class

  • Write and use generic methods

  • Assess the software engineering benefits of using generic methods

  • Assess the benefits and possible tradeoffs of using generic types vs Object type

2.4.1.1. Suggested Reading

Java Interlude 1 Generics from Data Structures and Abstractions with Java by Frank M. Carrano and Timothy Henry

2.4.2. Interactive: Generics Intro Video

Follow Along, Practice and Explore

Download to run and explore the java file (see below) from the video on your own in eclipse. You may download the standalone *.java file for this example. To run the standalone *.java file you will need to
  1. create a new Eclipse project, then

  2. create a package within the project called “example” (the package named at the top of the class MUST match the package the file is placed in within the Eclipse project), and finally

  3. download and import the standalone *.java file(s) to the created package.

ArrayBasics.java

2.4.3. Checkpoint 1

   «  2.3. Java Arrays   ::   Contents   ::   2.5. Lab 2 Polymorphism  »

nsf
Close Window