無名関数っぽく

最近こんなのばっかりだけど。


function add = new function() {
public Object def(Object arg) {
return arg[0].toString() + arg[1].toString();
}
};

String str = (String) add._("hello, ", "world.");
System.out.println(str);


public class function {

protected Object _this = null;

public function() {
}

public function(Object _this) {
this._this = _this;
}

public Object def(Object arg) {
throw new UnsupportedOperationException();
}

public Object _() {
return def(new Object[0]);
}

public Object _(Object arg1) {
Object args = { arg1 };
return def(args);
}

public Object _(Object arg1, Object arg2) {
Object args = { arg1, arg2 };
return def(args);
}

public Object _(Object arg1, Object arg2, Object arg3) {
Object[] args = { arg1, arg2, arg3 };
return def(args);
}

}