Scala Console.readInt已弃用

Adi*_*tya 7 scala

scala的命令行解释器显示:

scala> Console.readInt
warning: there was one deprecation warning; re-run with -deprecation for details
res0: Int = 65
Run Code Online (Sandbox Code Playgroud)

难道Console.readInt真的过时?如果是,采取输入的正确方法是什么?

我在OS X 10.10.5上使用Scala版本2.11.7.

elm*_*elm 13

在Scala 2.11中,您可以使用

scala.io.StdIn.readInt()
Run Code Online (Sandbox Code Playgroud)

要么

scala.io.StdIn.readLine().toInt
Run Code Online (Sandbox Code Playgroud)


Mar*_*rth 10

根据REPL的建议,运行scala -deprecation以获取更多信息:

scala -deprecation
Welcome to Scala version 2.11.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_79).
Type in expressions to have them evaluated.
Type :help for more information.

scala>  Console.readInt
<console>:8: warning: method readInt in class DeprecatedConsole is deprecated: Use the method in scala.io.StdIn
               Console.readInt
                       ^
Run Code Online (Sandbox Code Playgroud)