Is there any reason why this works: (implementing...
# language-proposals
e
Is there any reason why this works: (implementing a functional interface by delegation)
Copy code
object ColorEncoder : Encoder<Color> by { Encoder { appendable, t -> appendable.appendColor(t) }}()
But inlining the lambda body to this doesnt:
Copy code
object ColorEncoder : Encoder<Color> by Encoder { appendable, t -> appendable.appendColor(t) }
(I get that we can use a val instead, but would like to use objects to keep things consistent)
k
What if you put it in parentheses?
e
Parentheses work.. 👍
But it would be nice if they weren't required 🙂
But then it's simply a matter of how the code is parsed
b
Yeah it's probably just because it's lexically ambiguous. Same with extending an abstract class whose last primary constructor arg is a lambda. The lambda needs to be within the parentheses
Kotest and Spek come to mind, with test classes like this
Copy code
class MySpec : Spec({
  // tests
})