interface Liste {
  int length();
}
interface Cons extends Liste {
  Object getElem();
  void setElem(Object o);
  Liste getSuiv();
  void setSuiv(Liste tail);
}
interface Nil extends Liste {}

class ConcreteCons implements Cons{
  private Object o;
  private Liste suiv;
  public ConcreteCons(Object o, Liste suiv) {
    this.o = o;
    this.suiv = suiv;
  }
  public Object getElem() { return o; }
  public void setElem(Object o) { this.o = o; }
  public Liste getSuiv() { return suiv; }
  public void setSuiv(Liste suiv) { this.suiv = suiv; }
  public int length() { return getSuiv().length()+1; }
  public String toString() { return o + " " + suiv.toString(); }
}

class ConcreteNil implements Nil {
  private static ConcreteNil instance = null;
  private ConcreteNil() {};
  public static Liste getNil() { 
    if (instance == null) 
      instance = new ConcreteNil();
    return instance;
  }
  public int length() { return 0; }
  public String toString() { return "."; }
}

class TestListe{
  public static void main(String[] args) {
    Liste l = new ConcreteCons(new String("alpha"),
                  new ConcreteCons(new Integer(2), ConcreteNil.getNil()));
    System.out.println("liste de longueur "+ l.length());
    System.out.println("liste : "+ l);
  }

}


