Home CPSC 330

Generics Exercise

Objective

To become more familiar with Java generics.

Task

For this lab, you will be changing this hash table class to use generics instead of Object references. As it currently stands, there is nothing to stop someone from using different types of keys and values in the table. You will change the class and the main program to use generics instead.


Details

  1. Download the HashExercise.java file.
  2. Change the class HashTable to be generic. It should take two type parameters: the type of the key and the type of the value.
  3. When multiple type parameters are used, they are separated by commas.
  4. Change each reference to "Object" in the class to one of the two type parameters.
  5. Change the main function to supply the type String for the key and Integer for the value.

Submitting

When your program works, email the code to ifinlay@umw.edu.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.