Facts to Know ------------- * Consider a simple solution to a "String wrapper object": MyStringWrapper.java * Create your own similar wrapper for ints. See MyIntegerWrapper.java for solution. * Create your own similar wrapper for Student objects. See MyStudentWrapper.java for solution. * All of these solutions are similar to one another requiring only minor changes. It seem like a waste to have to create separate classes for such similar behavior! To the rescue: generic classes * generic classes: - allow the actions to the class to be applied to any object - the "type" of object to be worked with is passed on object creation - see MyGenericWrapper.java (and its driver GenericDriver.java) ... with this one class we are able to wrap any type of object! (NOTE: in order to store simple types (like int, double, char) we have to use the built-in wrapper classes (Integer, Double, Character) that pretty much work like the MyIntegerWrapper class except that Java will automatically wrap and unwrap them for us without having to explicity call their getters and setters! ------------------------------------------------------------------------------- * Sometimes the generic class you are creating needs to be able to compare its objects to one another. This is a challenge because we don't know ahead of time which types of objects we'll be storing ... and each kind of object has its own definition of how it should be compared to objects of its type. * Java solves this problem by allowing us to require objects that will be stored in our generic class to have defined a .compareTo() method * NOTE: all classes in Java inherit from Object (google "java object") which includes .toString(), .equals(Object), and other methods ... conspicously missing is .compareTo() * Any class the defines int compareTo(T other) is said to "implement the Comparable interface". - In our generic class we require objects stored to implement the Comparable inteface (See MyGenericComparableWrapper.java) - In any class of object we intend to store in our generic class we override .compareTo() and we announce to the world that we have done so. See ComparableStudent.java - To see it in use: GenericComparableDriver.java *