脱糖的好处是可以用来查看implicit转换点,scala里这个功能虽然强大,但其实也是挺头疼的。
脱糖的方法:
1. scala -Xprint:typer [filename.scala] 脚本脱糖
2. scala -Xprint:typer -e 'for(i <- 1 to 10) println' 表达式脱糖
3. scala控制台表达式脱糖
scala> import reflect.runtime.universe._
scala> reify( for(i <- 1 to 10) println(i) )
res0: reflect.runtime.universe.Expr[Unit] = Expr[Unit](scala.this.Predef.intWrapper(1).to(10).foreach(((i) => scala.this.Predef.println(i))))
scala> show(res0)
res9: String = Expr[Unit](scala.this.Predef.intWrapper(1).to(10).foreach(((i) => scala.this.Predef.println(i))))
scala> show(res0.tree)
res10: String = scala.this.Predef.intWrapper(1).to(10).foreach(((i) => scala.this.Predef.println(i)))