glenkpeterson01/03/2022, 10:43 PM
I understand that
val dotOne: Double = "0.1".toDouble() assertSame(dotOne, dotOne) expected: java.lang.Double@76774d21<0.1> but was: java.lang.Double@68be905c<0.1>
uses referential equality (checks that the parameters have the same virtual memory address) and should function like the
because they are primitives and could be boxed to different objects before being compared for referential equality. But, when I declare a variable, I would expect it to have the same virtual memory address as itself. Be referentially (and structurally) equivalent to itself. Can I declare my variable somehow to not be compiled away to two different primitives that happen to have different virtual memory addresses?
0.1 !== 0.1
ephemient01/03/2022, 10:44 PM
glenkpeterson01/03/2022, 10:46 PM
ephemient01/03/2022, 10:47 PM
as described in the article, LongCache is not tunable, and neither are the
glenkpeterson01/03/2022, 10:55 PM
@Suppress("RedundantNullableReturnType") val dotOne: Double? = 0.1 assertSame(dotOne, dotOne) // Yup, same!
Vampire01/03/2022, 11:15 PM
is compiled down to be a real primitve at runtime. And then when you use it as argument to an
it gets autoboxed.