【发布时间】:2016-01-04 08:47:16
【问题描述】:
我对 Lisp 中的 lambda 函数有很好的了解。 Java 似乎没有 Lisp 那样的灵活性。我必须如何考虑 Java 中的 lambda? 鉴于下面的代码,我该怎么做?
public class Draw {
GraphicsContext gc;
static void draw(double x, double y, double w, double h, boolean drawRect) {
if (drawRect) {
gc.fillRect(x, y, w, h);
} else {
gc.strokeRect(x, y, w, h);
}
}
// How do I do that?
static void drawWithLambda(double x, double y, double w, double h /**, lambda */) {
lambda(x, y, w, h);
}
public static void main(String[] args) {
draw(0, 0, 50, 50, false); // OK
drawWithLambda(0, 0, 50, 50, GraphicsContext::fillRect); // Ok?
}
}
【问题讨论】: