Hey, I’m trying to get a data class to make a defe...
# announcements
d
Hey, I’m trying to get a data class to make a defensive copy of a list when it’s created. Normally I would do this in the constructor or maybe an init, but all parameters in a data class have to be var or val which interferes with that plan. Currently I’ve come up with a hack, I was wondering if anyone knew of a better solution?
Copy code
data class Foo(val string: String, val num: Int, val riskyList: List<Int>, val hackToChangeSignature: Unit) {
    constructor(string: String, num: Int, riskyList: List<Int>) : this(string, num, ArrayList(riskyList), Unit)
}