当我在2上调用+时,我得到了一个Int,但是当使用显式方法调用完成时,我得到了Double.
scala> 2+2
res1: Int = 4
scala> 2.+(2)
res2: Double = 4.0
Run Code Online (Sandbox Code Playgroud)
看起来.+()是在隐式转换为Int到Double的情况下调用的.
scala> 2.+
<console>:16: error: ambiguous reference to overloaded definition,
both method + in class Double of type (x: Char)Double
and method + in class Double of type (x: Short)Double
match expected type ?
2.+
^
Run Code Online (Sandbox Code Playgroud)
为什么会这样 ?
scala ×1