I would suggest that this is an extension of this sidebar or box in the Good Book, which expresses the Least Surprise Principle:
http://www.artima.com/pins1ed/functions-and-closures.html#8.7
Or don't call it βLeast Surprise,β but fewer than two surprises.
Consider the following case when you ask the compiler to choose between two inherited functions. If the usual overload rules apply, he will select the method defined in the subclass. But is that a good policy?
scala> class Foo { | def f(x: Int, y: Int) = x + y | } defined class Foo scala> class Bar extends Foo { | def f(x: Int, y: String) = x + y.toInt | } defined class Bar scala> class Baz extends Bar { | val f = super.f(1, _)
In an object-oriented world, there are too many ways to surprise yourself, so there is a small tax on payment. Income tax.
(Note that in this example, resolution overload is possible, but by specifying f(1, _: MyWhatever) , we determined what applicability means.)
source share