How are Java generics different from C++ templates? Why can't I use int as a parameter?

后端 未结 8 1375
眼角桃花
眼角桃花 2020-12-12 19:02

I am trying to create

ArrayList myList = new ArrayList();

in Java but that does not work.

Can someone explain

8条回答
  •  眼角桃花
    2020-12-12 19:32

    that's because int is a primitive, it is a known issue.

    If you really wanted to, you can subclass/write your own collection that can do that.

提交回复
热议问题