Stefan Oltmann
05/02/2024, 3:51 PMMyId(1) === MyId(1)
not true
?
Why does it still see two object references?
There can't be two "instances" of a primitive long on the JVM.
(Also 1L === 1L
is true.)
@JvmInline
value class MyId(
val value: Long
)
Michael Krussel
05/02/2024, 4:04 PMBecause inline classes may be represented both as the underlying value and as a wrapper, referential equality is pointless for them and is therefore prohibited.https://kotlinlang.org/docs/inline-classes.html
ephemient
05/02/2024, 5:02 PMAlsoonly somewhat accidentally, on most JVMsis true.1L === 1L
"128".toLongOrNull() !== "128".toLongOrNull()
and there's ways to bypass the small number cache even for smaller constantsCLOVIS
05/03/2024, 7:45 AM1L === 1L
is deprecated (CTRL ALT H to see warnings) and will be forbidden in the future (for the reasons explained by @ephemient).Stefan Oltmann
05/03/2024, 7:50 AMStefan Oltmann
05/03/2024, 7:51 AMCLOVIS
05/03/2024, 9:19 AMStefan Oltmann
05/03/2024, 9:20 AMStefan Oltmann
05/03/2024, 9:21 AM