elect
05/02/2019, 8:31 AMinfix operator fun <N> N.minus(other: N): N where N : Number, N : Comparable<N> =
when {
this is Byte && other is Byte -> this - other
this is Short && other is Short -> this - other
this is Int && other is Int -> this - other
// this is Long && other is Long -> this - other
// this is Float && other is Float -> this - other
else -> error("Invalid operand types")
} as N
Everything works fine, smart casting is kicking in properly.
However if I comment out one the last two lines, then it cast automatically the result to Any
... ??karelpeeters
05/03/2019, 12:02 PMkarelpeeters
05/03/2019, 12:03 PMelect
05/03/2019, 12:03 PMkarelpeeters
05/03/2019, 12:03 PMelect
05/03/2019, 12:03 PMkarelpeeters
05/03/2019, 12:04 PMelect
05/03/2019, 12:04 PMkarelpeeters
05/03/2019, 12:06 PM-
on Byte
and Short
returns an Int
.elect
05/03/2019, 12:07 PMkarelpeeters
05/03/2019, 12:08 PMval x: Byte = ...
val y: Byte = ...
val r = x - y
karelpeeters
05/03/2019, 12:08 PMr
has type Int
.elect
05/03/2019, 12:09 PMelect
05/03/2019, 12:09 PMkarelpeeters
05/03/2019, 12:09 PM