Gasan
12/20/2023, 9:25 PMGasan
12/20/2023, 9:34 PMGasan
12/20/2023, 9:38 PMGasan
12/20/2023, 9:40 PMGasan
12/20/2023, 9:43 PMGasan
12/20/2023, 11:18 PMGoetz Markgraf
12/21/2023, 7:33 AM.copy()) that contains the second link.Gasan
12/21/2023, 9:17 AMparent = Parent()
child = Child(parent)
parent.copy(child = child)
The child of the parent has a link to the old parent without children, not the new one.
For circular references some form of mutability is required. See options in previous replies.Goetz Markgraf
12/21/2023, 9:45 AMGasan
03/18/2024, 5:20 PMdata class Entity(val name, val parent: Entity?, var children: List<Entity>?)
1. parent and children is a part of the data class because I want to copy() them
2. I must override equals(), hashCode() and toString() otherwise I get stack overflow error.