4 ms·
Y'know that's really funny.I often refer to the way lambdas only capture final variables as an example of the absolute brilliance of Java's language design. Rat
by kjeetgill 4y ago
Y'know that's really funny.I often refer to the way lambdas only capture final variables as an example of the absolute brilliance of Java's language design. Rather than a poor consideration I think it's a hallmark of how the obvious choice would be the worse choice in language design.
It a) preserves a principled confinement that the local scope provides, and b) removes all ambiguity around variables across lambdas, assignments inside or outside a closure before or after a stack frame collapses.
- SeanLuke 4y ago> Y'know that's really funny.I often refer to the way lambdas only capture final variables as an example of the absolute brilliance of Java's language design. This was done not for any principled reason at all: but rather because real closures would require heap allocation, and early users were spooked that heap allocation would be too slow. Otherwise Guy Steele (of Scheme and CL fame) would have definitely inserted them. He supposed that one day Java would fix this. https://web.archive.org/web/20090309081331/http://article.gmane.org/gmane.comp.lang.lightweight/2274 https://web.archive.org/web/20090309081331/http://article.gm...
- kjeetgill 4y ago> This was done not for any principled reason at all In light of all my praise for it that's devastating to hear, haha. I still think it was a brilliant move but now I can't fawn over it. Edit: on reading this I don't get it what they're taking about, we do get a heap allocation per lambda, identically to a record with the captured variables. Thanks for filling me in on dinner of the history of all of this.