上QQ阅读APP看书,第一时间看更新
Using the Scala Console
The Scala console, also called Scala REPL (short for Read-Eval-Print-Loop), allows you to execute bits of code without having to compile them beforehand. It is a very convenient tool to experiment with the language or when you want to explore the capabilities of a library.
In the console, type 1+1 after the scala> prompt and hit Ctrl + Enter or cmd + Enter:
scala> 1+1
The console displays the result of the evaluation, like so:
res0: Int = 2
What happened here? The REPL compiled, evaluated the expression 1+1, and automatically assigned it to a variable named res0. This variable is of type Int, and its value is 2.