Java generics - ArrayList initialization

后端 未结 6 1643
南方客
南方客 2020-12-02 13:58

It is known that arraylist init. should be like this

ArrayList a = new ArrayList();
ArrayList a = new ArrayList

        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 14:18

    Think of the ? as to mean "unknown". Thus, "ArrayList" is to say "an unknown type that (or as long as it)extends Object". Therefore, needful to say, arrayList.add(3) would be putting something you know, into an unknown. I.e 'Forgetting'.

提交回复
热议问题