The output is
BADDCD, without a newline. Method overloading chooses a signature using static types, including the instantiated class type parameter; numeric widening can make a Double parameter applicable to an Int argument.a.m(o1)choosesm(Int), which is more specific than the polymorphic method:B.a.m(o2)usesm[Double](Double):A.b.m(o1)comparesm(Any)andm(Double).Intcan widen toDouble, andDoubleis more specific thanAny:D.b.m(o2)choosesm(Double)overm(Any):D.c.m(o1)compares the instantiatedm(Int)withm(Double)and choosesm(Int):C.c.m(o2)can use onlym(Double):D.
The third call is the subtle one: the existence of
m(Any) does not prevent the more specific numeric overload from winning. These are Scala 2 method overloading and numeric widening rules. [ref] Articles by others on the same topic
There are currently no matching articles.