Java – Sam type optimization
The working document describing the status of project lambda refers to the so-called Sam (single abstract method) type As far as I know, the current lambda proposal does not affect the runtime, but the compiler can realize the automatic conversion from lambda expressions to these types
I think, ideally, instances of Sam types can be represented internally by function pointers Therefore, the JVM can avoid allocating memory for these instances
I wonder if modern virtual machines can provide such optimization
Solution
@Tam á s you should probably read this mailing list post from Brian Goetz:
http://mail.openjdk.java.net/pipermail/lambda-dev/2011-August/003877.html
Basically, lambda abstraction is currently implemented using objects However, it is designed to allow alternative implementations of lambda, which will be "smaller" than instances of classes
You can think of this as similar to auto Boxing - integers are boxed as integers, but have a "smaller" representation (such as integers)
Currently, Lambdas must be boxed into Sam type instances, and the B / C JVM currently cannot represent Lambdas with any smaller constructs In the future, there may be a new JVM standard that includes "primitive functions", which can represent lambda as something other than objects
Therefore, in order to answer your question, the optimization type you proposed may be possible, but it may be accompanied by "primitive functions" after Java 8 rather than implementation specific features