您可以使用“-print”作为编译器选项,scalac将删除所有特定于Scala的功能。
例如,下面是原始代码:
class Main
{
def test (x: Any) = x match {
case "Hello" => println ("Hello World")
case e: String => println ("String")
case i: Int => println ("Int")
case _ => println ("Something else")
}
}
如果你使用“scalac -print”来编译它,你会得到下面的Scala代码。
[[syntax trees at end of cleanup]]// Scala source: Test.scala
package <empty> {
class Main extends java.lang.Object with ScalaObject {
def test(x: java.lang.Object): Unit = {
<synthetic> val temp1: java.lang.Object = x;
if (temp1.==("Hello"))
{
scala.this.Predef.println("Hello World")
}
else
if (temp1.$isInstanceOf[java.lang.String]())
{
scala.this.Predef.println("String")
}
else
if (temp1.$isInstanceOf[Int]())
{
scala.this.Predef.println("Int")
}
else
{
scala.this.Predef.println("Something else")
}
};
def this(): Main = {
Main.super.this();
()
}
}
}