忽略scala的高级功能警告会导致什么后果?

时间:2014-12-31 16:53:57

标签: scala

我正在阅读关于隐式转化的this tutorial

我在REPL中使用-feature开关输入此代码:

object Rational {
    implicit def intToRational(x: Int): Rational = new Rational(x)
}

我收到了这个警告:

<console>:9: warning: implicit conversion method intToRational should be enabled
by making the implicit value scala.language.implicitConversions visible.
This can be achieved by adding the import clause 'import scala.language.implicitConversions'
or by setting the compiler option -language:implicitConversions.
See the Scala docs for value scala.language.implicitConversions for a discussion
why the feature should be explicitly enabled.
               implicit def intToRational(x: Int): Rational = new Rational(x)

但是当我运行这段代码时隐式转换工作正常:

scala> 12 * new Rational(1, 3)
res5: Rational = 4/1

如果我不遵循警告建议那么会有不良后果吗? (即添加import子句或设置编译器选项)

1 个答案:

答案 0 :(得分:3)

  1. 可能在未来的某个版本中,代码不会在不添加import子句的情况下编译。或者,如果您想使用-Xfatal-warnings

  2. 对于其他功能警告(特别是反射呼叫),您可能实际上想要消除它们;这并不适用于此特定警告。正如警告所示,请阅读文档。