Question: I have a data class like this -

```
data class User(val id: String, val name: String)

```

I want to use `apply` scope function to modify the values and return the modified object.

```
User("1", "Name").apply {
   this.id = "2" // Gives me error since val cannot be assigned
}

```

I do not want to make my data class immutable and also don't want to use `copy` function. How do I fix this?

Answer: 
You can use `copy` method with `data` classes:

```
val user1 = User("1", "Name")
val user2 = user1.copy(id = "2")

```
change like this `data class User(var id: String, var name: String)`