0

これに対する解決策があれば、それを見つけるのに苦労しています:

public class Generics {
    Map<Class<? extends SomeObject1>, SomeObject2>> map;
    map = new HashMap<Class<? extends SomeObject1>, SomeObject2>>();

    public static <E extends SomeObject1> SomeObject2 get(Class<E> c) {
        if (map.containsKey(c))
           return map.get(c);
        else {
           SomeObject2 o = new SomeObject2();
           map.put(c, o);
           return o;
        }
    }
}
...
//somewhere
public <T extends SomeObject1> void aMethod(AnInterestedClass<T> list) {
    // How to get the value from the map
    // knowing that the key is of type T?
    Generics.get(); 
}

アイデア?

4

1 に答える 1

1

タイプ eraserのため、クラス オブジェクトを に渡すことによってのみこれを行うことができますaMethodこの関連スレッドを参照してください。

于 2012-06-21T07:50:36.103 に答える