Matt Watson
02/17/2022, 10:13 AMinit {}
block?christophsturm
02/17/2022, 10:20 AMthanksforallthefish
02/17/2022, 10:21 AMclass Test : StringSpec() {
init {
"t" {
test()
}
}
private fun test() = ""
}
there is also this version
class Test : StringSpec({
fun test() = ""
"t" {
test()
}
})
but this one is a local function, https://kotlinlang.org/docs/functions.html#local-functions, as in the second example code is inside the constructorchristophsturm
02/17/2022, 10:23 AMCharles Flynn
02/17/2022, 10:29 AMinit
approach. I was originally avoiding this syntax as it seemed less clean than the constructor approach and has the effect of indenting everything. But it’s preferable to having to define functions upfront.