Remember, the labs are not for credit, just for practice! But that means you have to do them to learn anything.

1. Modifying the examples

Download the example code I’ve given, and try making the following changes (there are also comments in the files as hints):

2. Making and implementing a generic interface

  1. Make a MyList<T> generic interface
    • have a get method which takes an int and returns a T
      • this gets the item at the given index
    • have a set method which takes an int and a T
      • this sets the item at the given index to the new value
    • have a length method which returns an int
      • this returns the length of the list
  2. Make a DumbList<T> class which implements MyList<T>
    • store the data internally as an array of T
    • have the constructor take an int for the length of the List
      • you’ll have to write (T[])new Object[length] to allocate the array of T
    • implement the get, set, and length methods appropriately
  3. Make a driver (a main) which tests your DumbList
    • Use a couple different types (like DumbList<String> and something else)
    • Check that it works!