this is my code:
var header1: Record? = null
var header2: Record? = null
header2 = header1
header2.name = "new_name"
but header1.name changes too!
解决方案
You are just assigning the same object (same chunk of memory) to another variable. You need to somehow crate new instance and set all fields.
header2 = Record()
header2.name = header1.name
However in Kotlin, if the Record class was Data class, Kotlin would create a copy method for you.
data class Record(val name: String, ...)
...
header2 = header1.copy()
And copy method allows you to override fields you need to override.
header2 = header1.copy(name = "new_name")