scala的命令行解释器显示:
scala> Console.readInt
warning: there was one deprecation warning; re-run with -deprecation for details
res0: Int = 65
Console.readInt
真的被弃用了吗?如果是,采取输入的正确方法是什么?
我在OS X 10.10.5上使用Scala版本2.11.7。
答案 0 :(得分:12)
在Scala 2.11中,您可以使用
scala.io.StdIn.readInt()
或
scala.io.StdIn.readLine().toInt
答案 1 :(得分: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
^
答案 2 :(得分:2)
答案 3 :(得分:2)
或者,您可以使用导入来抑制警告:
import scala.io.StdIn._
val name = readLine("Your name:")
val age = readInt()
printf("Your name: %s, your age: %d\n", name, age)