runOnce
Remi Forax
forax at univ-mlv.fr
Tue Sep 25 02:59:44 PDT 2012
without any javac translation:
static class Runners {static { System.out.println("Boo!"); } static
void runOnce() {}}
public static void foo() {
Runners.runOnce();
}
Rémi
On 09/25/2012 11:45 AM, Aleksey Shipilev wrote:
> Hi guys,
>
> This thread [1] makes me thinking if we want to introduce something like
> runOnce() to record per-callsite invocation information. I.e. instead of
> messing with maps and flags to guard this behavior, one can possibly do:
>
> Runners.runOnce(() -> System.out.println("Boo!"));
>
> ...where runOnce will be desugared by Javac into indy call in which
> bootstrap method calls the callee, and then emits the constant callsite
> holding the result. This will effectively record the "invoked" property
> into callsite, so that this code:
>
> Runners.runOnce(() -> System.out.println("foo"));
> Runners.runOnce(() -> System.out.println("bar"));
>
> would yield:
> foo
> bar
>
> It might be yet another convenient way to make singletons (err...
> thread-safe identity caches), like:
>
> public T getInstance() { return Runners.runOnce(() -> new T()); }
>
> Was something like this considered before?
>
> -Aleksey.
>
> [1]
> http://mail.openjdk.java.net/pipermail/lambda-dev/2012-September/006015.html
More information about the lambda-libs-spec-experts
mailing list