Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Console.readInt deprecated

Tags:

scala

The command line interpreter of scala shows:

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

Is Console.readInt really deprecated? If yes, what is the correct way of taking input?

I am using Scala version 2.11.7 on OS X 10.10.5.

like image 282
Aditya Avatar asked Oct 22 '15 07:10

Aditya


4 Answers

In Scala 2.11 you can use

scala.io.StdIn.readInt()

or

scala.io.StdIn.readLine().toInt
like image 57
elm Avatar answered Nov 10 '22 07:11

elm


As suggested by the REPL, run scala -deprecation to get more info:

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
                       ^
like image 35
Marth Avatar answered Nov 10 '22 07:11

Marth


Or, you can use import to depress the warning:

import scala.io.StdIn._
val name = readLine("Your name:")
val age = readInt()
printf("Your name: %s, your age: %d\n", name, age)
like image 3
Ferris Avatar answered Nov 10 '22 08:11

Ferris


Check the Scala Api

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

It also has readInt method

like image 2
Fatih Donmez Avatar answered Nov 10 '22 07:11

Fatih Donmez