私のJava多形性には錆びます。HashMapsを使用したJavaの多態性の例を理解していません
私はクラスの商品があり、それから商品を拡張するクラスの服がある場合、なぜ以下のことができないのですか?
私は、私はこのコンパイルエラーを取得していないHashMap<String, Merchandise> stuff = new HashMap<String, Clothing>();
:
DataStore.java:5: error: incompatible types: HashMap<String,Clothing> cannot be converted to HashMap<String,Merchandise>
public static HashMap<String, Merchandise> tshirts = new HashMap<String, Clothing>();
も、商品アイテムのすべての衣料品ではありませんか? ^
「衣類」とは何ですか?靴ではありません –
服と商品の授業を精緻化できますか? –
Listのリストは、リストのサブクラスである可能性がありますか?なぜJavaのジェネリックは暗黙的に多相でないのですか?](http://stackoverflow.com/questions/2745265/is-listdog-a-subclass-of-listanimal-why-arent-javas-generics-implicitly-p) –
Savior