Created
March 7, 2022 00:44
-
-
Save wangyung/f17a0a50d5939e4b6037992a15877233 to your computer and use it in GitHub Desktop.
Revisions
-
wangyung created this gist
Mar 7, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ fun countingLambda(): () -> Int { var counter = 0 val incrementalCounter: () -> Int = { counter += 1 counter } return incrementalCounter } // decompiled java @NotNull public static final Function0<Integer> countingLambda() { void counter; Ref.IntRef intRef = new Ref.IntRef(); intRef.element = 0; Function0 incrementalCounter2 = (Function0)new Function0<Integer>((Ref.IntRef)counter){ final /* synthetic */ Ref.IntRef $counter; public final int invoke() { ++this.$counter.element; return this.$counter.element; } { this.$counter = intRef; super(0); } }; return incrementalCounter2; }