Skip to content
Anthony Christe edited this page Sep 20, 2013 · 3 revisions

Creating a Generic Class

  • Create a generic class "ThreeItemBox" that only accepts types that extend "Comparable"
  • Create three generic instance variables first, second, and third
  • Create a constructor which takes three generic variables and assigns them to first, second, and third
  • Create generic getters and setters for first, second, and third
  • Create a generic method "getSortedItems" which returns an ArrayList of the first, second, and third in sorted order (can use Collections.sort or compareTo).

To test your code

  • Create a ThreeItemBox for Integers, Doubles, and String with the following values passed to the constructor
  • Integers: 9, 5, 1
  • Doubles: 8.5, 100.0, 2.0
  • Strings: "poke", "ono", "ahi"
  • Print out the results of getSortedArrayList for each instance

Clone this wiki locally