저는 컴파일러 용 새로운 API를 가지고 놀았으며 2.11에서 다시 돌아 왔고 이상한 결과를 보았습니다.스칼라 IMain` v. 2.11의`(Int)`와`Int` 타입의 차이점은 무엇입니까?
Welcome to Scala version 2.11.0-20140415-163722-cac6383e66 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.tools.nsc.interpreter.IMain
import scala.tools.nsc.interpreter.IMain
scala> import scala.tools.nsc.Settings
import scala.tools.nsc.Settings
scala> val eng = new IMain(new IMain.Factory(), new Settings())
eng: scala.tools.nsc.interpreter.IMain = [email protected]
scala> eng.interpret("val x: Int = 2")
x: Int = 2
res0: scala.tools.nsc.interpreter.IR.Result = Success
scala> eng.valueOfTerm("x")
res2: Option[Any] = Some(2)
scala> eng.typeOfTerm("x")
res3: eng.global.Type =()Int
scala> eng.typeOfExpression("x")
res4: eng.global.Type = Int
scala> eng.typeOfExpression("x") =:= eng.global.definitions.IntTpe
res6: Boolean = true
scala> eng.typeOfTerm("x") =:= eng.global.definitions.IntTpe
res7: Boolean = false
당신이 볼 수 있듯이, typeOfTerm("x")
반환 ()Int
하지만 typeOfExpression("x")
반환 Int
: 여기 내 REPL 출력입니다. 나는 유형 ()Int
이 유형 Int
의 변수를 나타내는 경우라고 생각하지만, 나는 확신 할 수 없다. 누군가가 내 혼란을 확인하거나 교정 할 수 있고, 이에 대해 이야기하는 문서로 안내 할 수 있다면, 나는 그것을 고맙게 생각한다. 내가 찾을 수있는 반성 문서를 조사했지만 운이 없었습니다.
. 바보 같아요. 포장 개체가 만들어져 통역사에게 전송되는 방법을 추적하는 것을 기억하기 때문입니다. 감사! – TOB