Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala can't recognize which method to call

Tags:

scala

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

like image 975
amorfis Avatar asked Jan 28 '12 20:01

amorfis


1 Answers

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.

like image 129
Adam Zalcman Avatar answered Oct 21 '22 11:10

Adam Zalcman