Whats the use of saying <? extends SomeObject> instead of

后端 未结 5 1759
陌清茗
陌清茗 2020-11-27 18:54

So I was looking over some Java code and stumbled upon:

List l;

basically this list accepts all objects that ar

5条回答
  •  抹茶落季
    2020-11-27 19:36

    X cannot be added to List even if X can be converted to Y.

    So,in your second case if List l; was allowed to add subclass of X,that would break the basic principal of type safety

提交回复
热议问题