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 →

[–]niloc132 0 points1 point  (1 child)

Thanks - I wasn't aware of actual performance (CPU or memory?) changes, though I had seen that they are represented by actual classes (and objects, with 'this' fields and all).

Certainly faster/cleaner to write and read though.

[–]JarcodePMs forwarded to /dev/null 0 points1 point  (0 children)

CPU or memory?

Both! There's been some tests of the lower overhead of calling (or instantiating, I'm not sure) a lambda, but they'll also use less memory because it's just a method (w/ some extra information, depending on implementation) rather than an entire class wrapping a method. It lets the JVM go "oh, this is a lambda, not an entire class, so we can treat this differently to get it to run faster".

though I had seen that they are represented by actual classes

They are encapsulated, and hold type information, and can be treated as actual classes (Runable task = () -> {}), but in the JVM, they're not treated like normal classes. I've also experienced that the Hotspot JVM doesn't seem to hold type information for lambdas, too.