https://kotlinlang.org logo
Title
s

SerVB

04/07/2020, 12:37 PM
Haven't anyone created a ticket at https://youtrack.jetbrains.com/issues/KT to allow to extract lambda outside the constructor parameters? It will be great to have such a feature for kotest: instead of
class MyTest : FreeSpec({
    // ...
})
it will be possible to write like
class MyTest : FreeSpec {
    // ...
}
I've searched briefly by couldn't find.
m

Mike

04/07/2020, 12:56 PM
The test Lambda is a parameter to the constructor, hence the syntax. The only alternative is to use the
init
syntax, but personally, I think that's even less desirable.
s

SerVB

04/07/2020, 1:41 PM
@Mike, yep, I want to use the constructor syntax, but without round brackets
I've created a ticket, feel free to vote! https://youtrack.jetbrains.com/issue/KT-38082
m

Mike

04/07/2020, 1:56 PM
Question. How will the compiler differentiate between constructor and class definition without the parenthesis? And how much impact will it have on performance if it can? Still never hurts to ask.
Hmmm, never mind. If it was a class definition, one would require
class MyTest : FreeSpec() { .   }
s

SerVB

04/07/2020, 2:06 PM
How will the compiler differentiate between constructor and class definition without the parenthesis?
Just proposed the behavior in the ticket, thanks
s

sam

04/07/2020, 2:13 PM
This would be amazing
I voted