2014-04-16 2 views
1

복구 할 수없는 순환 해결 가져 오기가 발생하는 이유는 무엇입니까? 나는 객체 정의를 주석 처리했지만 여전히 작동하지 않습니다. 코드는 의미가 없지만 왜 컴파일되지 않는지 알고 싶습니다.스칼라 : 복구 할 수없는 순환 해결 가져 오기가 발생했습니다.

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 
이 이해가되지 않습니다 그것은 컴파일되지 않는 이유 : 당신은 abc 다음 패키지에서 첫 번째 요소를 재정의하려고 ( def abc[0]?) 가져

를 즉, 그 후에 당신이하려고하는

+0

'abc [O] = new test [O]'는 스칼라 구문에 의해 지원되지 않는 난센스 표현입니다 –

답변

2

유형 대신에 0 값을주는 특성 new test[O]의 인스턴스를 작성하십시오.

관련 문제