Why can't a Generic type containing a Generic type be assigned to a Generic typed class of wildcard type

前端 未结 2 1513
栀梦
栀梦 2021-01-02 11:03

Sorry if the title seems confusing, but some examples are in order.

Let\'s say I have some Java class with a generic type parameter:

public class Gen         


        
2条回答
  •  走了就别回头了
    2021-01-02 11:27

    Technically, that's because List> is not a subtype of List>. In order to make it work, you could do something like

    List> generic = stringy
    

    which should work as expected (though is pretty ugly...).

    See, for example, this SO question for more details

提交回复
热议问题