我的代码中有一个类型别名,如下所示:
type Time = Double
而且我经常在测试和应用程序中将 Long 值传递给使用这种类型的函数。例如:
def at(time : Time) : T = {
// Do Something
}
at(System.currentTimeMillis)
除非在我收到以下错误的测试中运行,否则此代码可以正常工作:
found : Long
required: com.github.oetzi.echo.Echo.Time
Note that implicit conversions are not applicable because they are ambiguous:
both method long2double in object Predef of type (x: Long)Double
and method longToDouble in trait NumericBaseMatchers of type (s: Long)Double
are possible conversion functions from Long to com.github.oetzi.echo.Echo.Time
查找后,NumericBaseMatchers
它似乎是 Specs 测试框架的一部分(我的测试是在 Specs 1 中编写的)。我尝试运行代码以在解释器中获取错误,并且在测试之外很好。
有什么办法可以消除歧义,以便将 Long 值传递给 Double/Time 函数?为什么 Specs 尝试创建自己的 LongToDouble 转换,而 Scala 已经提供了这种转换?