java可以运行编译的scala代码吗?

nan*_*nda 38 java scala

命令可以java运行编译的scala代码吗?如果是这样,为什么我们有一个独家命令scala

Lan*_*dei 48

You can run byte code generated by Scala if you include all necessary runtime libs for Scala (scala-library.jar, scala-swing.jar ...) in the classpath. The scala command does this automatically, and supports Scala specific command line arguments.


Thi*_*ilo 12

Yes, it can. Scala is compiled down to Java bytecode. But remember that it depends on the Scala runtime classes, so you need to still have Scala's jar files on the classpath.

If so, why do we have an exclusive command scala?

Convenience wrapper.


ata*_*man 5

Scala is designed to integrate easily with applications that run on modern virtual machines, primarily the Java virtual machine (JVM). The main Scala compiler, scalac, generates Java class files that can be run on the JVM. -> http://www.artima.com/scalazine/articles/steps.html

As long as you have installed the scala runtime you should be fine: compile classes with scalac and run them with java.