Wednesday, July 30, 2014

Lambdas in Java 8 Aren't Just Inner Classes

I've been watching quite a few instruction videos lately. One of my favorites is about how lambdas are implemented in the JVM. One would think they simply implemented lambdas as inner classes but they didn't. They used a the fancy invoke dynamic instruction to get more performance out of it. invoke dynamic is incredibly powerful. It's actually a JVM instruction that runs a custom method to figure out how to resolve the method call then caches it if the custom code says it's possible.

Check it out: Lambdas under the hood

For those whose eyeballs are allergic to video there's also this document which does a good job of explaining things too: Translation of Lambda Expressions


No comments: