mR_*_*r0g 5 java eclipse compiler-construction javac
Eclipse 3.4.Java编译器级别1.6 JRE IBM 1.6
我们有一个库类,我们无法改变它的形式.
import java.util.Hashtable;
public class A extends Hashtable {
...
}
Run Code Online (Sandbox Code Playgroud)
我们已经构建了一个实用程序类,以便于访问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;
}
}
Run Code Online (Sandbox Code Playgroud)
当我们尝试从另一个类调用其中一个构造函数时,会出现问题.
public class C {
public void stuff() {
A a = new A();
B b = new B(a);//Error in javac
}
}
Run Code Online (Sandbox Code Playgroud)
Eclipse编译时没有错误,当它通过ant javac和jenkins编译时,编译器会给出如下错误.
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);
Run Code Online (Sandbox Code Playgroud)
这个错误应该发生在javac吗?在我看来,eclipse在选择更具体的方法时是正确的.
| 归档时间: |
|
| 查看次数: |
1497 次 |
| 最近记录: |