I am not sure if I am clear with my title. In Swift I have this struct.
struct Movement {
let name: String
var reps: Int
}
let movement1 = Movement(name: "Push Ups", reps: 20)
var movementA = movement1
movementA.reps = 30
print(movement1.reps) // Prints 20
print(movementA.reps) // Prints 30
What is alternative in Kotlin (or Java)? The problem is that in my app I have a workout that consists of multiple movements. I append these movements to the MutableList and the problem appears when I have workout where a movement is repeated.
For example when I want to enter workout like:
20 Push Ups
30 Pull Ups
40 Push Ups
I end up with:
40 Push Ups
30 Pull Ups
40 Push Ups
At first, I select movement #1 and set reps of movement #1 but when I select movement #3 and set reps of movement #3 it overrides variables of movement #1.
Any idea?
I have tried something like this but it didn't work.
class Movement(name: String) {
var reps: Int? = null
}
val movement1 = Movement("Push Ups")
movement1.reps = 20
var movementA = movement1
movementA.reps = 30
Log.i("REPS1: ", movement1.reps.toString()) // 30
Log.i("REPSA: ", movementA.reps.toString()) // 30