I have this code
open class Shape { open fun number(m: Shape) = "1" open fun number(m: Rectangle) = "2"}class Rectangle : Shape() { override fun number(m: Shape) = "3" override fun number(m: Rectangle) = "4"}fun main() { val shape: Shape = Rectangle() println(shape.number(shape))}
I expected 4
to be printed, while it is 3
: how does dynamic dispatch work? the invoked function is Rectangle#number(Shape)
even tho the object is the same, shape
.