``` data class Foo private constructor (val a: Int...
# announcements
a
Copy code
data class Foo private constructor (val a: Int, val b: Int)

fun Foo(a: Int, b: Int) = ...
s
it looks like that results in a conflicting override (and an accidental recursive call)
and if I change the method name, I still can’t access the private constructor from a top-level function
a
function and data class must be in the same file
s
they’re declared literally one after another in my code
a
nvm ^^
I get a runtime exception
so the best way is to use a
companion object
with
operator fun invoke
1
that should work with a private constructor
s
oh wow, that works pretty well 👍
a
yes, just make sure you override
copy
s
How do you "override" a generated function?
s
I’m not sure that you can - I got a platform declaration clash when I tried
a
https://kotlinlang.org/docs/reference/data-classes.html#data-classes
If there are explicit implementations of equals(), hashCode() or toString() in the data class body or final implementations in a superclass, then these functions are not generated, and the existing implementations are used
and
Deriving a data class from a type that already has a copy(...) function with a matching signature is deprecated in Kotlin 1.2 and will be prohibited in Kotlin 1.3.
so you can't override
copy()
or
componentN()
😕
s
so it goes 😕
a
TIL wasn't aware that you can't override all methods that are generated
s
In this case it would help just to prohibit (make private) the
copy()
method. I think it would make sense to give a finer grain control over generated methods.