Consider the following Scala code:
object MainObject {
def main(args: Array[String]) {
import Integer.{
parseInt => atoi
}
println(atoi("5")+2);
println((args map atoi).foldLeft(0)(_ + _));
}
First println works fine and outputs 7, but the second one, attempting to map array of strings against a function atoi doesn't work,with error "value atoi is not a member of object java.lang.Integer"
What's the difference?
This is because it can't tell which atoi to use. There are two possibilities parseInt(String) and parseInt(String, int). From the REPL:
You need to say specifically which one to use, this will work:
This is not an answer to your question but you could use the
toInt
method fromStringOps
instead ofInteger.parseInt
.Looks like a bug. Here's a simpler example.