Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No DeepCopy on Collections #1

Closed
mustii82 opened this issue May 17, 2019 · 5 comments
Closed

No DeepCopy on Collections #1

mustii82 opened this issue May 17, 2019 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@mustii82
Copy link

mustii82 commented May 17, 2019

Hi under a DeepCopy my Understandig is that even the members should be deepcopys but in this Code:

val speaker = Speaker("Benny Huo", arrayListOf(1, 2, 3, 4))
    val talk = Talk("DataClass in Action", speaker)
    val newTalk = talk.deepCopy()

    talk.speaker.arrayList.removeAt(0)

    println(talk)
    println(newTalk)

The list will change on both Objects

@bennyhuo
Copy link
Owner

Yes, you're right. Only data class annotated by @DeepCopy will be handled with deepCopy method.

@bennyhuo bennyhuo added the enhancement New feature or request label May 18, 2019
@bennyhuo bennyhuo added this to the 1.3.0 milestone May 18, 2019
@bennyhuo
Copy link
Owner

Element type in collections could be any type which may not be designed to be deep copied or even copied.
Maybe we should seek a way to copy collections with a generic data class type.

@bennyhuo
Copy link
Owner

Try the new branch v1.3. Use bunch of reflections to do the collection deep copy.

@mustii82
Copy link
Author

will the objects inside a collection also be deep copied?

@bennyhuo
Copy link
Owner

will the objects inside a collection also be deep copied?

If the type of the element is Collection or data class annotated with DeepCopy, it will be deep copied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants