No, you'd have to make a factory method then and m...
# getting-started
d
No, you'd have to make a factory method then and make the constructor private, which means you also need to override
copy
. If you use
invoke
in the companion object, you can make it look like a normal constructor call though.
j
diesieben07: Ok thanks. I will give it a try.
Do you have any example for a companion object with "invoke"?
d
Copy code
data class Foo private constructor(val bla: List<String>) {
    companion object {
        operator fun invoke(bla: List<String>) = Foo(bla.toList())
    }
}
Can be called like
Foo(<myList>)
, which will call
invoke
.
j
Thanks.