TwoClocks
08/03/2021, 5:25 PMInt etc) copy on assignment, but classes create a reference on assignment. (see this simple example : https://pl.kotl.in/tTP-Co4SS). If I want to make my own numeric-ish type is there a way to behave the same as Int on assignment?mcpiroman
08/03/2021, 5:45 PMTwoClocks
08/03/2021, 5:50 PM+= ?TwoClocks
08/03/2021, 5:56 PMInt immutable as well?mcpiroman
08/03/2021, 5:57 PMmcpiroman
08/03/2021, 5:58 PMmcpiroman
08/03/2021, 6:03 PM@JvmInline
value class A(val value: Int) {
operator fun plus(other: A) = A(value + other.value)
}
var x = A(0)
x += A(1)
compiles fine for meTwoClocks
08/03/2021, 6:22 PMTwoClocks
08/03/2021, 6:24 PM@JvmInline. It doesn't seem to exist in kotlin.jvm.*mcpiroman
08/03/2021, 6:26 PMTwoClocks
08/03/2021, 6:27 PM.? operator...TwoClocks
08/03/2021, 6:28 PMTwoClocks
08/03/2021, 6:29 PMJvmInline in the 1.4.x compiler, but then not actually have it... oh well.mcpiroman
08/03/2021, 6:35 PM