Hullaballoonatic
04/17/2019, 8:00 PMdata class Foo {
companion object {
operator fun invoke(): Foo {
}
}
}
Andrew Gazelka
04/17/2019, 8:07 PMHullaballoonatic
04/17/2019, 8:09 PMbdawg.io
04/17/2019, 9:36 PMfun Foo() = Foo(someValue)
insteadgildor
04/18/2019, 1:06 AMfun Foo() = Foo(someValue)
is also fine, but it will conflict with class if class has the same signature of constructor, so you cannot have private constructor and builder with some additional logic:
class Foo private constructor(val value: String)
fun Foo(rawWalue: String?) = Foo(requireNotNull(rawWalue))
bdawg.io
04/18/2019, 2:33 AMFoo()
via companion object invoke()
still just as ambiguous if the class has that same constructor?gildor
04/18/2019, 2:33 AM