忽略scala';s高级功能警告?
我在读关于隐式转换的书 我在REPL中使用忽略scala';s高级功能警告?,scala,Scala,我在读关于隐式转换的书 我在REPL中使用-功能开关输入了此代码: 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 sca
-功能
开关输入了此代码:
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)
那么,如果我不遵守警告建议,是否会产生不良后果?(即添加导入子句或设置编译器选项)
-Xfatal warnings
只有一个结果是编译器输出中的警告太多,这很烦人。导入该功能后,将不会有任何警告,您只需明确说明。每年春季晚些时候都会有许多不想要的小猫出生。如果您可以等到那时,也许每次发出警告时,其中一个被杀死就不会那么可怕了。@som snytt:那么隐式功能是一个设计错误吗?这并不意味着。有些人不喜欢SIP-18是选择性加入,所以你必须宣布“我不是白痴,让我这么做吧”,但我已经开始欣赏它的安全特性。所以进口就像汽车上的安全带。加州说“点击它或票。”
scala> 12 * new Rational(1, 3)
res5: Rational = 4/1