Skip to content

Ambiguous reference when invoking Properties.putAll() in Java 11 #10418

Closed
scala/scala
#7966
@ijuma

Description

@ijuma

Java 8:

scala> import java.util.Properties
import java.util.Properties

scala> new Properties().putAll(new Properties)

Java 9:

scala> import java.util.Properties
import java.util.Properties

scala> new Properties().putAll(new Properties)
<console>:13: error: 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)
       new Properties().putAll(new Properties)

The reason is that the following override was added in Java 9 in order to use a ConcurrentHashMap as the underlying implementation:

    @Override
    public synchronized void putAll(Map<?, ?> t) {
        map.putAll(t);
    }

scalac seems to think it's an overload instead of an override. The Hashtable method is defined as (K = Object and V = Object):

    public synchronized void putAll(Map<? extends K, ? extends V> t) {
        for (Map.Entry<? extends K, ? extends V> e : t.entrySet())
            put(e.getKey(), e.getValue());
    }

I found this while trying to compile Apache Kafka with Java 9.

Is it worth doing anything about this apart from documenting it somewhere?

Metadata

Metadata

Assignees

Labels

fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)jdk11

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions