Linux command
scala 命令
趣味
复制后可按需替换文件名、目录或参数。
常用示例
Start REPL
scala
Run script
scala [script.scala]
Run with classpath
scala -cp [lib.jar] [script.scala]
Evaluate expression
scala -e "println(1 + 2)"
Run compiled class
scala [ClassName]
With specific JVM memory
scala -J-Xmx[2g] [script.scala]
Run in explain mode
scala -explain [script.scala]
说明
scala runs Scala programs and provides an interactive REPL. Scala combines object-oriented and functional programming on the JVM. The REPL evaluates expressions and shows results with types. Tab completion helps explore APIs. :help shows REPL commands. Scripts run directly without compilation. The Scala 3 runner can execute .scala files as scripts with dependencies. Classpath specifies libraries and compiled classes. Maven coordinates can specify dependencies in Scala 3. Compiler explanations help understand complex error messages. The explain mode provides detailed reasoning. The language supports type inference, pattern matching, implicits, and higher-order functions. It interoperates with Java seamlessly.
参数
- -cp, -classpath _PATH_
- Set classpath for class files and libraries.
- -e _EXPR_
- Evaluate expression and print the result.
- -J _FLAG_
- Pass flag to JVM (e.g., -J-Xmx2g).
- -deprecation
- Show deprecation warnings.
- -explain
- Explain errors in detail with additional context.
- -feature
- Show feature warnings for advanced language features.
- -help
- Show help.
- -version
- Show version.
- -X
- Show advanced compiler options.
- -Y
- Show private compiler options.
FAQ
What is the scala command used for?
scala runs Scala programs and provides an interactive REPL. Scala combines object-oriented and functional programming on the JVM. The REPL evaluates expressions and shows results with types. Tab completion helps explore APIs. :help shows REPL commands. Scripts run directly without compilation. The Scala 3 runner can execute .scala files as scripts with dependencies. Classpath specifies libraries and compiled classes. Maven coordinates can specify dependencies in Scala 3. Compiler explanations help understand complex error messages. The explain mode provides detailed reasoning. The language supports type inference, pattern matching, implicits, and higher-order functions. It interoperates with Java seamlessly.
How do I run a basic scala example?
Run `scala` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -cp, -classpath _PATH_ do in scala?
Set classpath for class files and libraries.