Comment by vbezhenar
Class is a set of functions. Closure is one function.
In old Java, it really was a class. In new Java, I'm not 100% sure anymore, but with verbose syntax it'll be an class. I made it as verbose as possible:
Function<Integer, Integer> adder(int x) {
class Adder implements Function<Integer, Integer> {
int x1;
@Override Integer apply(Integer y) {
return x1 + y;
}
}
Adder adder = new Adder();
adder.x1 = x;
return adder;
}
and a bit less verbose with modern Java: Function<Integer, Integer> adder(int x) {
return (y) -> x + y;
}
So closure could be definitely be considered as a very simple class.