Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
忽略scala';s高级功能警告?_Scala - Fatal编程技术网

忽略scala';s高级功能警告?

忽略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

我在读关于隐式转换的书

我在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 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)
那么,如果我不遵守警告建议,是否会产生不良后果?(即添加导入子句或设置编译器选项)

  • 可能在将来的某个版本中,如果不添加import子句,代码将无法编译。或者如果您想使用
    -Xfatal warnings

  • 对于其他功能警告(特别是反射性呼叫),您可能实际上希望消除它们;这并不适用于此特定警告。按照警告建议阅读文档


  • 只有一个结果是编译器输出中的警告太多,这很烦人。导入该功能后,将不会有任何警告,您只需明确说明。每年春季晚些时候都会有许多不想要的小猫出生。如果您可以等到那时,也许每次发出警告时,其中一个被杀死就不会那么可怕了。@som snytt:那么隐式功能是一个设计错误吗?这并不意味着。有些人不喜欢SIP-18是选择性加入,所以你必须宣布“我不是白痴,让我这么做吧”,但我已经开始欣赏它的安全特性。所以进口就像汽车上的安全带。加州说“点击它或票。”
    scala> 12 * new Rational(1, 3)
    res5: Rational = 4/1