178 |
|
* @throws NullPointerException if the specified collection is null |
179 |
|
*/ |
180 |
|
public ArrayList(Collection<? extends E> c) { |
181 |
< |
elementData = c.toArray(); |
182 |
< |
if ((size = elementData.length) != 0) { |
183 |
< |
// defend against c.toArray (incorrectly) not returning Object[] |
184 |
< |
// (see e.g. https://bugs.openjdk.java.net/browse/JDK-6260652) |
185 |
< |
if (elementData.getClass() != Object[].class) |
186 |
< |
elementData = Arrays.copyOf(elementData, size, Object[].class); |
181 |
> |
Object[] a = c.toArray(); |
182 |
> |
if ((size = a.length) != 0) { |
183 |
> |
if (c.getClass() == ArrayList.class) { |
184 |
> |
elementData = a; |
185 |
> |
} else { |
186 |
> |
elementData = Arrays.copyOf(a, size, Object[].class); |
187 |
> |
} |
188 |
|
} else { |
189 |
|
// replace with empty array. |
190 |
< |
this.elementData = EMPTY_ELEMENTDATA; |
190 |
> |
elementData = EMPTY_ELEMENTDATA; |
191 |
|
} |
192 |
|
} |
193 |
|
|