4 ms·
You're confusing structural / nominal typing with first class functions. What Java lacks is the latter, while closures do not depend on the former, which is wha
by barrkel 15y ago
You're confusing structural / nominal typing with first class functions. What Java lacks is the latter, while closures do not depend on the former, which is what you're talking about.
For example, C# supports function types, but it can have hundreds of function types (it calls them delegate types) for a function that takes one int and returns one int:
delegate int Func1(int x);
delegate int Func2(int x);
delegate int Func3(int x);
and so on; all these function types are incompatible with one another.
I believe the distinctive feature of closures is closing over (hence the name) the outer lexical environment and binding to variables in the outer environment, in such a way that those variables are available during evaluation. Which is exactly what an anonymous class lets you have (so long as locals in the outer scope are declared final).