I want to run a bit of Java in Scala console. Here’s what I get:
scala> String.format("hello %d",3);
<console>:8: error: overloaded method value format with alternatives:
(java.util.Locale,java.lang.String,<repeated...>[java.lang.Object])java.lang.String <and>
(java.lang.String,<repeated...>[java.lang.Object])java.lang.String
cannot be applied to (java.lang.String, Int)
String.format("hello %d",3);
Why Scala can’t recognize which method to call, if argument set is different, and the ones I provide are quite unambigous?
What is strange, the same message appears also when I try to call function with arguments which don’t match to any of both argument sets, e.g. String.format()
I was using scala 2.9.1
Your arguments don’t match the function prototype. You’re calling the function with second argument
scala.Intwhich is not ajava.lang.Object.Convert it to
java.lang.Integerand it will work.See also boxing and unboxing in Scala.