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.Int
which is not a java.lang.Object
.
Convert it to java.lang.Integer
and it will work.
See also boxing and unboxing in Scala.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With