为什么隐式转换不会引发编译时错误?

时间:2020-03-11 09:11:43

标签: scala

Scala中的以下语句引发运行时错误:

val a = 10: Object

error: the result type of an implicit conversion must be more specific than Object
   val a = 10: Object
           ^

如果Scala中不允许上述隐式转换,那么为什么Scala在编译时不抛出错误?

1 个答案:

答案 0 :(得分:2)

您为什么认为这是运行时错误?不是:

$ scalac impl.scala                                                                  
impl.scala:3: error: the result type of an implicit conversion must be more specific than Object
val a = 10: Object
        ^
one error found