glenkpeterson
01/03/2022, 10:43 PMval dotOne: Double = "0.1".toDouble()
assertSame(dotOne, dotOne)
expected: java.lang.Double@76774d21<0.1> but was: java.lang.Double@68be905c<0.1>
I understand that assertSame
uses referential equality (checks that the parameters have the same virtual memory address) and should function like the ===
operator. 0.1 !== 0.1
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?ephemient
01/03/2022, 10:44 PMglenkpeterson
01/03/2022, 10:46 PMephemient
01/03/2022, 10:47 PM-XX:AutoBoxCacheMax=
as described in the article, LongCache is not tunable, and neither are the Boolean.TRUE
and Boolean.FALSE
static instancesglenkpeterson
01/03/2022, 10:55 PM@Suppress("RedundantNullableReturnType")
val dotOne: Double? = 0.1
assertSame(dotOne, dotOne) // Yup, same!
Vampire
01/03/2022, 11:15 PMDouble
is compiled down to be a real primitve at runtime. And then when you use it as argument to an Object
method like assertSame
it gets autoboxed.