3 ms·
In my opinion, Java wouldn't need to use lambdas as often if it had a more powerful object model. You'd define methods instead of pass lambda's as parameters. L
by tabtab 7y ago
In my opinion, Java wouldn't need to use lambdas as often if it had a more powerful object model. You'd define methods instead of pass lambda's as parameters. Lambda's are often a band-aid for a weak object model.
For example, if I want to define an "on click" GUI event handler for a given button, the more natural approach would be to define an "onClick" method for that button's object. But you can't do that in Java in a simple way the way you could in say SmallTalk. Thus, one typically has to send a lambda to a "listener" object, which is unnatural.
- TeMPOraL 7y agoI think the two things you described are essentially identical. Defining a onClick method on an object is equivalent to giving the onClick method a function with implementation in it. +/- whatever shenanigans your object system plays with methods. Java does indeed have a very weak object model, though it improves slowly over time. But rejecting to use those improvements because it's "clever code" is arguably just dumb.
- tabtab 7y agoI agree there is or can be a lot of overlap between OOP and aspects of functional. With some diligent language factoring, I suspect they can be blurred to be one in the same. That way one doesn't have to learn two different sets of rules and syntax. But, I'm not sure Java can fix such cleanly without breaking backward compatibility.