我有一个带有一些这样的构造函数的类:
public MyClass(Control caller, WritableList elements, String pattern) {
this(caller, elements, pattern, new LabelProvider());
}
public MyClass(Control caller, WritableList elements, String pattern, ILabelProvider labelProvider) {
super(caller.getShell(), labelProvider);
// ...
}
public MyClass(Control caller, Collection<String> elements, String pattern) {
super(caller.getShell(), new LabelProvider());
// ...
}
如果我尝试使用以下方法创建它的实例:
new MyClass(getControl(), getWritableList(), "test");
或这个:
new MyClass(getControl(), (WritableList) getWritableList(), "test");
Eclipse 抱怨构造函数不明确。但是,如果我这样做:
new MyClass(getControl(), (Collection<SomeType>) getWritableList(), "test");
一切安好。我想知道可能是什么问题?我使用org.eclipse.core.databinding.observable.list.WritableList
的是 RCP 框架附带的。
编辑:
我认为WritableList
扩展Collection
接口可能是错误,但我创建了一些测试类,结果事实并非如此:
public class Main {
/**
* Main.
* @param args
*/
public static void main(String[] args) {
TestClass obj = new TestClass(getTypeAInstance(), "asd");
}
public static SomeTypeA getTypeAInstance() {
return new SomeTypeA();
}
public static interface SomeInterface<T> {
}
@SuppressWarnings("rawtypes")
public static interface SomeInterfaceExtensionWithoutTypeParam extends SomeInterface {
}
public static interface SomeInterfaceExtensionWithTypeParam<T> extends SomeInterface<T> {
}
@SuppressWarnings("rawtypes")
public static interface SomeIntermediateInterface extends SomeInterfaceExtensionWithoutTypeParam, SomeInterfaceExtensionWithTypeParam {
}
public static class SomeTypeA implements SomeIntermediateInterface {
}
public static class TestClass {
public TestClass(SomeInterface<String> i, String s) {
}
public TestClass(SomeTypeA a, String s) {
}
}
}