enter image description here When I'm learning array's knowledge, there are such descriptions saying array holds reference variables(not object itself) or primitives, as opposed to ArrayList
holding an object. I want to confirm why ArrayList
can hold object rather than reference variables. enter image description here
You're just taking everything out of context...
if you would read further in the second image then you'd understand that there exists primitve arrays ( int[]
) but no such thing as a primitive List ( List<int>
).
Instead you have to use wrapper classes ( List<Integer>
).
Then don't mess up the definition of Object
and Object reference
because in java you never can have an Object
in place, you're always working with Object-references
(and also with primitives
to be really clear).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.