クラスA
、B
、C
およびextends D
、extends 、 extends があります。B
A
C
A
D
A
次ArrayList
の s があり、それぞれにいくつかの要素があります。
ArrayList<B> b;
ArrayList<? extends A> mix = b;
変数に、またはmix
型の要素を含めるつもりでした。タイプの要素を次のように追加しようとしました:B
C
D
C
mix
mix.add(anElementOfTypeC);
しかし、IDE ではそうすることができず、次のように表示されます。
anElementOfTypeC は、CAP#1 が新しい型変数である呼び出し変換のメソッドによって CAP#1 に変換できません。CAP#1 は、? のキャプチャから A を拡張します。Aを拡張します
<? extends A>
を正しく使用しましたか? どうすればこれを解決できますか?