Why can not I add an object of type Object into a List<?>?

后端 未结 5 1525
忘了有多久
忘了有多久 2020-12-21 12:03

As far as I understand a List is definds as a list of some specific , yet unknown type . So whatever is the parameter type of this List

5条回答
  •  太阳男子
    2020-12-21 12:43

    List listObj can point to any type of List that can store different kind of objects.

    How do you think, would it be safe to let it add any objects if for example

    List listObj = new ArrayList();
    listObj.add(new Object());
    

提交回复
热议问题