1

In the library I use there are overloaded methods:

  • put(String key, Integer value)
  • put(String key, Long value)
  • put(String key, Double value)
  • put(String key, Float value)

I'm trying to put String with Int value there but I get the following error:

Error:(41) ambiguous reference to overloaded definition,
both method put in class ContentValues of type (x$1: String, x$2: Double)Unit
and  method put in class ContentValues of type (x$1: String, x$2: Float)Unit
match argument types (String,Long)

What can I do in that case?

Kamil Lelonek
  • 14,592
  • 14
  • 66
  • 90

1 Answers1

3

You are trying to put an Int, but there is no overloaded method that takes that, so the compiler tries to use an implicit conversion. My guess is that it sees that you can implicitly convert this to a Double or a Float, but it doesn't know which one to use. So let's help it out:

val myJavaInteger: java.lang.Integer = myScalaInt

Now call put with myJavaInterger, there will be no confusion because there is an overloaded put method which accepts java.lang.Integer.

stan
  • 4,885
  • 5
  • 49
  • 72