class EmptyListException extends RuntimeException {} public class List { private final T head; private final List tail; private List(T head, List tail) { this.head = head; this.tail = tail; } public static List nil() { return new List(null, null); } private boolean isNil() { return tail == null; } public T head() { if (isNil()) throw new EmptyListException(); return head; } public List tail() { if (isNil()) throw new EmptyListException(); return tail; } public List add(T o) { return new List(o, this); } public static char char1(List l) { return l.head().charAt(0); } public static void main(String[] args) { List l = List.nil().add("Banana"); System.out.println(char1(l)); } }