A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nipafx/demo-lambda-instances below:

nipafx/demo-lambda-instances: Demonstrates a detail of the lambda expression evaluation regarding the creation and reuse of instances.

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.

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4