Scala .readInt Console Deprecated

The scala command line interpreter shows:

scala> Console.readInt
warning: there was one deprecation warning; re-run with -deprecation for details
res0: Int = 65

Is it Console.readIntreally obsolete? If so, what is the correct way to enter data?

I am using scala version 2.11.7 on OS X 10.10.5.

+4
source share
4 answers

In Scala 2.11 you can use

scala.io.StdIn.readInt()

or

scala.io.StdIn.readLine().toInt
+9
source

As suggested by REPL, run scala -deprecationto get more information:

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
                       ^
+10
source

Tick Scala Api

(Since version 2.11.0) Use the method in scala.io.StdIn

It also has a method. readInt

+2
source

Or you can use import to warn:

import scala.io.StdIn._
val name = readLine("Your name:")
val age = readInt()
printf("Your name: %s, your age: %d\n", name, age)
+1
source

Source: https://habr.com/ru/post/1612703/


All Articles