Ambiguous constructor reference in javac but not in Eclipse

Eclipse 3.4. Java 1.6 compiler level. JRE IBM 1.6

We have a library class that we cannot change, which has a form.

import java.util.Hashtable;
public class A extends Hashtable {
  ...
}

And we created a utility class to provide easy access to A.

public class B {
  private A a;
  public B() {
    this.a = new A();
  }
  public B(final A props) {
    this.a = props;
  }
  public B(final Map<String, String> props) {
    this();
    for (String key : props.keySet()) {
      add(key, props.get(key));
    }
  }
  @SuppressWarnings("unchecked")
  public B add(final String name, final Object value) {
    a.put(name, value);
    return this;
  }
}

The problem arises when we try to call one of the constructors from another class.

public class C {

  public void stuff() {
    A a = new A();
    B b = new B(a);//Error in javac
  }
}

Eclipse compiles this without errors, and when it is compiled through ant javac and jenkins, the compiler throws an error, as shown below.

reference to B is ambiguous, both method B(com.foo.A) in com.bar.B and method B(java.util.Map<java.lang.String,java.lang.String>) in com.bar.B match
    [javac]         B b = new B(a);

If this error occurs in javac? In my opinion, the eclipse is correct in choosing a more specific method.

+5
source share
3 answers

Since HashTable implements Map, there is ambiguity. HThis contains some goot info:

Java

0

, Hashtable, . , , Java - , - , () . , , .

0

A Hashtable, Hashtable Map, , A , Map.

public B(final A props) public B(final Map<String, String> props) , .

.

-1
source

All Articles