Constants
がMyInterface
のサブタイプであるにも関わらず、Iterable<Constants>
はIterable<MyInterface>
のサブタイプではないので、あなたがIterable<? extends MyInterface>
代わりのIterable<MyInterface>
を使用する必要がある - と私はあなたの理由を紹介します:それはそうだった場合のは、使用してみましょう(
をList
次の例ではIterable
の代わりに)、私はこれを行うことができます:
List<Constant> constantsList = new ArrayList<Constants>(); // list of constants
List<MyInterface> ifaceList = constantsList; // you said this would be OK ...
// assume MyOtherImplementation is another implmentation of MyInterface
ifaceList.add(new MyOtherImplementation()); // OK, MyOtherImplementation implements MyInterface
Constant myConst = constantsList.get(0); // Oops! I just got an instance of MyOtherImplementation from List<Constant> - not cool.
それは実際に動作します。それではすぐに回答を受け付けます。どうもありがとう! – tannerli