import java.util.function.Function; abstract class List { private final T head; private final List tail; protected List() { this.head = null; this.tail = null; } private List(T head, List tail) { this.head = head; this.tail = tail; } protected T getHead() { return head; } private static RecCall> firstHelper(final List list, final Function f) { return cont(new RecCall.Continue>(firstHelper(list.tail, f))); } public static RecCall cont(final RecCall next) { return new RecCall.Continue(next); } } interface Result {} interface RecCall { public static class Continue implements RecCall { private final RecCall next; public Continue(RecCall next) { this.next = next; } } }