Skip to content

Instantly share code, notes, and snippets.

@ikhoon
Created September 30, 2019 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikhoon/1fb7094bcf24f50e9dbe755b74c62cf9 to your computer and use it in GitHub Desktop.
Save ikhoon/1fb7094bcf24f50e9dbe755b74c62cf9 to your computer and use it in GitHub Desktop.
Check java lambda instance is singleton.
String foo() {
return "abc";
}
String foo(Supplier<String> s) {
System.out.println(s);
return "abc " + s.get();
}
@Test
public void sample() {
IntStream.range(1, 10)
.forEach(i -> foo(this::foo));
}
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@6b53e23f
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@400cff1a
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@275710fc
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@525f1e4e
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@75f9eccc
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@52aa2946
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@4de5031f
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@67e2d983
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@5d47c63f
@ikhoon
Copy link
Author

ikhoon commented Sep 30, 2019

   static String bar() {
        return "abc";
    }

    @Test
    public void lambdaStatic() {
        IntStream.range(1, 10)
                 .forEach(i -> foo(LambdaInstance::bar));
    }
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
// playground.LambdaInstance$$Lambda$43/0x00000008000e8040@62e136d3
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment