import java.util.concurrent.Callable;

class NotBoundFunctionException extends Exception { }

abstract class Function<A,R> implements Callable<R> {
    private A _arg;
    public A arg() { return this._arg;}
    public void arg(A arg) { this._arg = arg; }

    public Function() {}
    public Function(A arg) { this.arg(arg); }

    public Function<A,R> bind(A arg) { this.arg(arg); return this; }

    protected abstract R callMe();
    public R call() throws Exception {
        if ( this._arg == null) { throw new NotBoundFunctionException(); }
        return this.callMe();
    }
    public R call(A arg) throws Exception {
        return this.bind(arg).call();
    }
}

class LambdaCallable {
    public static void main(String[] args) {

         Function<Integer,Integer> doubler = new Function<Integer,Integer>(){
            protected Integer callMe() { return 2*this.arg(); }};

        try {

            doubler.arg(21);
            System.out.println(doubler.call());

            System.out.println(doubler.bind(12).call());

            System.out.println(doubler.call(21));

        } catch (Exception e) { System.exit(1); }
    }
}
