Page 1 of 1

[HD Pg 366, Sec. 12.4.3 - disadvantages-of-arraylist]

Posted: Wed Jul 21, 2021 7:40 am
by enthunoob
As written on page 88 as well, that Arraylist (autoboxes stored primitives cause it) only works with objects, what causes this? Why does ArrayList only work with objects?/Why do simple Arrays allow primitives?

But later it might have dawned on me: cause all of the arguments of ArrayList-methods are generic-types. Please verify

Re: [HD Pg 366, Sec. 12.4.3 - disadvantages-of-arraylist]

Posted: Wed Jul 21, 2021 10:16 am
by admin
ArrayList is like any other class written by an application programmer. It doesn't work with primitives because it is not designed by the class designers that way. They designed it to work with objects only.

It is a design decision taken most likely because it uses an Object array as the internal data structure and you can't store primitives in an array of objects and the didn't think that ArrayList of primitives would be very useful. (Please note that this is my guess only.)