bbaldino
04/02/2019, 4:40 PMRtpSequenceNumber
is my inline class here, it wraps an Int
hudsonb
04/02/2019, 4:55 PMhudsonb
04/02/2019, 4:59 PMbbaldino
04/02/2019, 5:21 PMbbaldino
04/02/2019, 5:35 PM!=
, as in if (inlineClassInstance1 != inlineClassInstance2
...but from that article i wouldn't think that would need boxing? maybe i misread. i do have a custom compareTo
implemented for it, is that why?hudsonb
04/02/2019, 7:11 PMbbaldino
04/02/2019, 7:36 PMbbaldino
04/02/2019, 7:39 PMhudsonb
04/03/2019, 1:29 PM!=
hudsonb
04/03/2019, 1:30 PMinline class Test(val n: Int)
fun main() {
val t1 = Test(1)
val t2 = Test(2)
println(t1 != t2)
}
hudsonb
04/03/2019, 1:56 PMinline class Test(val n: Int)
fun main() {
val t1 = Test(1)
val t2 = Test(2)
println(t1.n != t2.n)
}
hudsonb
04/03/2019, 1:57 PMequals
takes an `Object`/`Any` so it has to be boxedbbaldino
04/03/2019, 4:09 PMhudsonb
04/03/2019, 4:11 PMfun equals(other: Any?): Boolean
, since it takes Any?
as a parameter, it'll be boxed.bbaldino
04/03/2019, 4:11 PMhudsonb
04/03/2019, 4:13 PM!=
on the wrapped Int
is the only way to avoid it. That means it can't be private
though which kinda sucksbbaldino
04/03/2019, 4:13 PMhudsonb
04/03/2019, 4:16 PMinline class Test(val value: Int) {
infix fun eq(other: Test): Boolean = value == other.value
}
fun main() {
val t1 = Test(1)
val t2 = Test(2)
println(t1 eq t2)
}
bbaldino
04/03/2019, 4:18 PMbbaldino
04/03/2019, 4:18 PMhudsonb
04/03/2019, 4:19 PMbbaldino
04/03/2019, 4:35 PM// Reserved method for specialized equals to avoid boxing
public final static equals-impl0(II)Z
hudsonb
04/03/2019, 4:43 PMequals-impl
and delegating to that:
public static boolean equals_impl(int var0, @Nullable Object var1)
public boolean equals(Object var1) {
return equals-impl(this.value, var1);
}
but main
is clearly boxing:
boolean var2 = Intrinsics.areEqual(Test.box-impl(t1), Test.box-impl(t2));
bbaldino
04/03/2019, 4:46 PMbbaldino
04/03/2019, 5:03 PM