Skip to content

Arrays.asList doesn’t return the ArrayList you know

April 9, 2013

I recently wrongly assumed that java.util.Arrays.asList, would return java.util.ArrayList, but it doesn’t. Instead, java.util.Arrays has a private static nested class that extends AbstractList on it’s own. Calling a method like ‘retainAll()” fails because of missing methods that exist in java.util.ArrayList, but NOT in java.util.Arrays$ArrayList.

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/util/Arrays.java#Arrays.asList%28java.lang.Object%5B%5D%29

Advertisements

From → Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: