【发布时间】:2012-03-11 12:51:02
【问题描述】:
当我在 2 上调用 + 时,我得到一个 Int 返回,但是当它使用显式方法调用完成时,我得到的是 Double。
scala> 2+2
res1: Int = 4
scala> 2.+(2)
res2: Double = 4.0
似乎在将 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.+
^
为什么会这样?
【问题讨论】:
标签: scala