OO Programming with Java


Templates

In particular, the example application can use a "generic" type of values as follow:

public class GOrder<T> {
  private T         value;
  private GOrder<T> next;
  
  public GOrder(T value, GOrder next) {
    this.value = value; this.next  = next; }
  public GOrder() { this(null,null); }

  public void add(T value) {
    if (this.value == null) {
      this.value = value; return; }
    if (this.next == null) {
      this.next = new GOrder(value,null); return; }
    this.next.add(value);
  }
}

3 - 13