Approximating closures in Java

May 16, 2003 18:16 · 104 words · 1 minute read

Charles Miller wrote a nice article: The Fishbowl: Closures and Java: a Tutorial. He talks about using inner classes to somewhat approximate closures. He also says that “To implement them properly would involve making changes to some pretty fundamental parts of the JVM”, which I’m not sure is completely true. It may be possible for Sun to create java.lang.Function and then add some syntactic sugar to the compiler to create

1) Functions that can be passed around easily, which is something that is potentially quite useful

2) Real closures (but there may be more issues to the scoping that I’m just not thinking through)