scala:遇到不可恢复的循环解析导入

时间:2014-04-16 08:55:45

标签: scala

为什么我遇到遇到不可恢复的循环解析导入?我注释掉了对象定义,但仍然无法工作。代码是无意义的,但只是想知道它为什么不编译。

object abc
{
 trait test[T]{
   def prt(x:T):Unit
}
//object test
  val b="hello word"
}

object my extends App{
   import abc._
   def abc[O]=new test[O]{
     def prt(x:Int)=println("testabcd")
   }
   println(b)
   println("test1")
}


sbt run
[info] Set current project to myfirstproject (in build file:/D:/my/test/)
[info] Compiling 1 Scala source to D:\my\test\target\scala-2.10\classes...
[error] D:\my\test\Hello.scala:11: encountered unrecoverable cycle resolving import.
[error] Note: this is often due in part to a class depending on a definition nested within its companion.
[error] If applicable, you may wish to try moving some members into another object.
[error]    import abc._
[error]           ^
[error] D:\my\test\Hello.scala:15: not found: value b
[error]    println(b)
[error]            ^
[error] two errors found
[error] (compile:compile) Compilation failed
[error] Total time: 3 s, completed Apr 16, 2014 4:45:35 AM

1 个答案:

答案 0 :(得分:2)

它没有意义,这就是为什么它不能编译:)

您正在导入abc然后尝试重新定义包中的第一个元素(def abc[0]?),之后您尝试创建特征new test[O]的实例,其值为0而不是类型。