5 ms·
This was a mistake. Actually, Gosling said he was planning to add lambdas but ran out of time. Some APIs were excessively verbose due to the lack of lambdas, w
by nextos 4y ago
This was a mistake. Actually, Gosling said he was planning to add lambdas but ran out of time.
Some APIs were excessively verbose due to the lack of lambdas, which were emulated using anonymous inner classes.
- agumonkey 4y agoInteresting, not what I recall (but my readings on this were quick). AFAIK it was carefully not pursued because they wanted to make everything as classes so they went with AIC. If you have a link, please share.
- nextos 4y agoThere might be some better (primary) sources: Gosling say closures represent the realization of a dream that was postponed in Java's early days and resulted in the invention of inner classes - "an uncomfortable compromise" that failed to provide the desired level of simplification. He notes criticism that closures are too complex, but advises people to read "through all of what Neal has written". https://www.theregister.com/2008/02/01/java_closures/ https://www.theregister.com/2008/02/01/java_closures/
- agumonkey 4y agoI think I read about early java design on c2. I might dig later.
- Viliam1234 4y ago> they wanted to make everything as classes Java is mostly about interfaces. Classes are just a way to implement them. This is one of the differences between Java and C/C++.
- kjeetgill 4y agoI mean, from your comments I don't expect you to like it, but lambdas are still mostly anonymous classes. The way lambdas bind to SAM interfaces and implement them is pretty different than say scala or even C/C++ function pointers where the necessary parameter/return type can be encoded into a variables type and referred to directly. I think that's cool enough but one of the subtle elements of design brilliance was how local variables must be final to be bound into a closure. There's a whole class of ambiguity removed and static guarantees in the face of concurrency that I think goes unappreciated.
- kaba0 4y agoI’m not sure whether you mean semantically or in implementation, but from the latter point of view they are rather compiled as static functions and an invokedynamic instruction that will resolve to them at first occurrence.
- kjeetgill 4y ago> I’m not sure whether you mean semantically or in implementation I'll have to mull over that. I guess to me they seem aligned enough, thats why it feels so elegant. Or maybe I haven't thought about it enough. > rather compiled as static functions and an invokedynamic instruction that will resolve to them at first occurrence Yea! but that invokedynamic calls the lambda metafactory which spins up bytecode for a class with 2 things: a) a constructor to bind the values captured from the scope the lambda was declared in to fields, and b) an instance method that feeds those fields to the static function you referred to. I'd argue that that class is essentially an anonymous class. Maybe I'm easily impressed, but that functional programming <-> OOP duality of lambdas/closures and SAM interfaces always felt profound. We can get along! There's no need for this feud!
- kaba0 4y agoI just wanted to add something I knew on the topic, but you seem to know much more! Thanks for the interesting read, and it is indeed a cool duality!