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
Copy code
class MyTest : FreeSpec({
// ...
})
it will be possible to write like
Copy code
class MyTest : FreeSpec {
// ...
}
SerVB
04/07/2020, 12:38 PM
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
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.
Mike
04/07/2020, 2:01 PM
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?