yolocat
01/19/2024, 4:57 PMmolikuner
01/19/2024, 5:17 PMinit
block:
class Foo(arg: String) {
init {
println("Hello, $arg")
}
}
Another way would be to make the constructor private and create a function instead:
class Foo private constructor() {
companion object {
operator fun invoke(arg: String): Foo {
println("Hello, $arg")
return Foo()
}
}
}
Or, yet another way of doing it:
private class Foo : IFoo
fun Foo(arg: String): IFoo {
println("Hello, $arg")
return Foo()
}
vladimirsitnikov
01/19/2024, 5:17 PMfun ClassName() { ... }
yolocat
01/19/2024, 6:01 PMyolocat
01/19/2024, 6:02 PMvladimirsitnikov
01/19/2024, 6:49 PMyolocat
01/19/2024, 8:51 PMclass MyUI : UI() {
override fun build(): Component {
root {
add(VStack {
add(Button(“click”))
})
}
}
}
this is my current setup, but I want to remove the add
calls which looks redundant
edit: with VStack and Button both being classes extending Component, and root func creating a top level parent Componentmolikuner
01/20/2024, 12:04 AMadd
is defined for you, but assuming it's a function like this:
interface UiBuilder {
fun add(...)
}
You could use extension functions:
fun UiBuilder.VStack(builder: VStackUiBuilder.() -> Unit) { add(...) }