Java Generics — Assigning a list of subclass to a list of superclass

前端 未结 7 2097
我寻月下人不归
我寻月下人不归 2020-12-07 02:00

I have a basic question regarding assignment of a list of subclass to a list of superclass.

So I have something like the following:

Class B extends          


        
7条回答
  •  误落风尘
    2020-12-07 02:40

    Because generics are strict type safe.

    You can have

    List aList = bList;
    

    It says aList can hold list of any type which is an A

提交回复
热议问题