List<? extends MyType>

后端 未结 5 1870
旧时难觅i
旧时难觅i 2020-11-27 17:44

I have a Java question about generics. I declared a generic list:

List listOfMyType;

Then in some method I try ins

5条回答
  •  一整个雨季
    2020-11-27 18:38

    There is a similar thread here: How can elements be added to a wildcard generic collection?

    To get an idea of how generics works check out this example:

        List sfoo = new ArrayList();
        List foo;
        List tmp;
    
        tmp = sfoo;
        foo = (List) tmp;
    

    The thing is, that wasn't designed for local/member variables, but for function signatures, that's why it's so ass-backwards.

提交回复
热议问题