https://kotlinlang.org logo
#codereview
Title
# codereview
g

griffio

08/12/2018, 7:11 PM
@antoin_m Yes - from my understanding it will work as expected with the type simply as the Vec sealed class. No extra casting is needed. The compiler will correctly show the “exhaustive check” if you add another data class.
Copy code
operator fun Double.times(vec: Vec) = when (vec) {
    is Vec2 -> vec.copy(this * vec.x, this * vec.y)
    is Vec3 -> vec.copy(this * vec.x, this * vec.y, this * vec.z)
}
a

antoin_m

08/13/2018, 7:38 AM
Yeah but then it returns a
Vec
and not a
Vec2
or
Vec3
4 Views