4

次のようなコンストラクタを持つクラスがあります。

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.WritableListRCP フレームワークに付属するものを使用しています。

編集:

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) {
        }
    }
}
4

1 に答える 1

0

問題は Eclipse 独自の Java コンパイラーにあったようです。

于 2012-12-20T12:56:38.643 に答える