The standard output is three lines:This is program output, excluding any interactive interpreter's display of returned values. The calls
A
2.3
Ba.m(1) and b.m(5.6) compute squares without printing. In A, the concrete m(Int) wins over the generic method at argument 1; the string and 2.3 use m[T] and print their arguments.For
b: B[Any], the class type parameter has already become Any, so the two alternatives are m(Any) and m(Double), rather than a method with its own freely inferred type parameter. The Double alternative is more specific. It accepts 4 by numeric widening, so b.m(4) computes 16.0 without printing; b.m("B") prints B; b.m(5.6) computes a square without printing. These are applications of the Scala 2.11 method overloading rules, with the arithmetic return values discarded in statement position.[ref]https://www.scala-lang.org/files/archive/spec/2.11/06-expressions.html#overloading-resolution. Scala 2.11 Language Specification, §6.26.3, overload applicability and specificity
Articles by others on the same topic
There are currently no matching articles.