Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, ArrayLists are array-backed, but Arrays.asList instantiates a List and does not instantiate an array.



As I explained, List is an interface. You can't instantiate it, values are instances of types not interfaces.

All that return type is telling you is, surprise, asList promises what you're getting implements the List interface. See if you can guess how you can implement the List interface using an Array. Still struggling, here's the one line of a typical implementation:

return new Arrays.ArrayList(a);


You should at least try to be correct if you're going to be so insufferable about it.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: