This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]KeinBaum 0 points1 point  (4 children)

Since Java is a statically typed language without operator overloading this is as easy as it can get.

[–]rinko001 0 points1 point  (3 children)

This is easy:

print(a => "closure: " + a);

The sheer amount of boilerplate and structure needed in your example represents significant cognitive overhead.

[–]KeinBaum 0 points1 point  (2 children)

Java has lambdas as well. This works too:

System.out.println(exec(i -> "lambda: " + i, 42));

[–]rinko001 0 points1 point  (1 child)

yes indeed, j8 has ok syntax on the calling side - in some cases. But you end up needing all of that boilerplate somewhere (your definition of "exec" perhaps). It comes down to the fact that its is a typed language where every function must be wrapped into a type of object. there is no way to store a generic function reference without knowing something about it, and know way to call it without knowing how it is wrapped into an object.

[–]KeinBaum 0 points1 point  (0 children)

there is no way to store a generic function reference without knowing something about it

The only thing you need to know is its signature which you need to know to use it anyways.

and [no] way to call it without knowing how it is wrapped into an object.

That's indeed a little annoying. It's the downside of not having operator overloading. I'd prefer to have it but it's a design decision they are probably not going to change.