Created
March 22, 2023 07:22
-
-
Save leolin310148/a162a147af80480650d1252fabfa77bd to your computer and use it in GitHub Desktop.
kotlin operation function return self can invoke forever
This file contains 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 characters
enum class Foo { | |
HELLO, | |
WORLD, | |
// | |
; | |
var i = 0 | |
} | |
class FooBuilderSpec { | |
operator fun Foo.invoke(i: Int): Foo { | |
this.i++ | |
return this | |
} | |
} | |
class FooBuilder(dsl: FooBuilderSpec.() -> Unit = {}) { | |
init { | |
FooBuilderSpec().also(dsl) | |
} | |
} | |
fun main() { | |
FooBuilder { | |
Foo.HELLO(1)(2)(3)(4)(5)(6)(7)(8)(9)(10).i | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment