本文介绍了Scala 伴生类警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Scala 编程的新手,有人可以在警告原因下面解释我吗?
I am new to Scala programming, can someone explain me below warning reason?
我试图找到原因,它似乎更早修复了:https://issues.scala-lang.org/browse/SI-6439
I tried to find the reason and it seems like a big fixed earlier: https://issues.scala-lang.org/browse/SI-6439
那为什么我会收到这个警告?
So why I am getting this warning?
推荐答案
这是特定于 REPL(读取评估打印循环)的,因为它无法知道用户输入何时结束.
This is specific to the REPL (Read Evaluate Print Loop), since it can't know when user input ends.
使用 :paste
绕过它:
scala> class A {}
defined class A
scala> object A {}
defined object A
warning: previously defined class A is not a companion to object A.
Companions must be defined together; you may wish to use :paste mode for this.
scala> :paste
// Entering paste mode (ctrl-D to finish)
class A {}
object A {}
// Exiting paste mode, now interpreting.
defined class A
defined object A
这篇关于Scala 伴生类警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!