Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous reference error compiling Scala with Java 9

Currently I am facing the following compilation error in Scala against Java 9:

: ambiguous reference to overloaded definition,
both method putAll in class Properties of type (x$1: java.util.Map[_, _])Unit
and  method putAll in class Hashtable of type (x$1: java.util.Map[_ <: Object, _ <: Object])Unit
match argument types (java.util.Properties)
  newProps.putAll(props)

newProps is defined as:

  val newProps = new Properties

I tried variants of newProps.asInstanceOf[java.util.Map[...]] but got different compilation errors.

Any hint is welcome.

like image 822
Ted Avatar asked Jun 14 '26 06:06

Ted


1 Answers

As @Ted pointed out this is a known issue. One workardound would be to subsitute putAll with something like this:

props.forEach((k, v) => newProps.put(k, v))

Note that by doing this your operation is not atomic anymore but most probably this is not important in your case.

like image 100
SergGr Avatar answered Jun 15 '26 21:06

SergGr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!