https://kotlinlang.org logo
#announcements
Title
# announcements
z

Zemeio

06/08/2019, 6:15 PM
Hi guys. Is there a simple way to do cyclic data classes? If I do it normaly most of the methods will break.
s

Shawn

06/08/2019, 6:17 PM
Would you mind expanding on what you mean by “cyclic”?
z

Zemeio

06/08/2019, 6:19 PM
data class Parent(child: Child); data class Child(parent: Parent) Something like this.
e

elizarov

06/08/2019, 7:26 PM
Why would you want it to be a data-class? What for?
3
z

Zemeio

06/09/2019, 1:08 AM
They are classes I use on services, and might want to save on database. I researched a bit, and found I can just define the parent reference outside of the propeties. However, I think I would have to make it nullable, which I`m not sure I want.
Like data class Parent(child: Child); data class Child(){var parent: Parent?} or something.
l

louiscad

06/09/2019, 8:23 AM
That doesn't tell why you want the
data
modifier, does it?
z

Zemeio

06/09/2019, 3:09 PM
Aren`t data classes used for seralizing?
e

elizarov

06/09/2019, 4:40 PM
Usually “serailizable” classes are serailized. Data classes are used for simple data containers.
4 Views