OO Programming with Java


Templates

A sample use is then:

public static void main(String[] args) {
  Order o = new Order();
  o.add("Chicken"); o.add("French Fries"); o.add("Salad");
  System.out.println(o); // NB. toString has to be 'overloaded'
} // Chicken, French Fries, Salad
  1. What happens is one wants now a list of Person ? of Integers ? ... of T ?
    The code stays the same except for the value that must be Person, then Integer ... then T that is a type variable.

  2. It is possible to use Object (that represents "anything") and cast ... or to use "templates" and let the compiler makes a transformation to the previous elements.


2 - 13