Skip to content

Demonstrates a detail of the lambda expression evaluation regarding the creation and reuse of instances.

License

Notifications You must be signed in to change notification settings

nipafx/demo-lambda-instances

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Instances of Non-Capturing Lambdas

This project provides the code samples for the CodeFX post about instance identity of lambda evaluations. In particular it demonstrates that the current JRE (or at least Oracle JRE 1.8.0_25-b18 for Win 64) reuses the same instance for repeated evaluations of the same non-capturing lambda expression.

Code

There is not much code. The ImmediateFuture is a functional interface which extends Future and only leaves get() unimplemented. The FutureFactory uses lambda expressions to create instances of this particular Future. Finally CreatingInstances shows that the non-capturing lambda expression used in FutureFactory.createWithDefaultResult() always returns the same instance.

This example uses Future to simulate a somewhat realistic use case and to show that this is by no means limited to "obvious" situations where identity of new functional interfaces like Supplier or Consumer are handled.

About

Demonstrates a detail of the lambda expression evaluation regarding the creation and reuse of instances.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages