mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8203184: List.copyOf() fails to copy sublists
Reviewed-by: psandoz
This commit is contained in:
parent
693a6dd27a
commit
277b35da28
3 changed files with 30 additions and 7 deletions
|
@ -83,6 +83,16 @@ class ImmutableCollections {
|
|||
|
||||
// ---------- List Implementations ----------
|
||||
|
||||
// make a copy, short-circuiting based on implementation class
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E> List<E> listCopy(Collection<? extends E> coll) {
|
||||
if (coll instanceof AbstractImmutableList && coll.getClass() != SubList.class) {
|
||||
return (List<E>)coll;
|
||||
} else {
|
||||
return (List<E>)List.of(coll.toArray());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E> List<E> emptyList() {
|
||||
return (List<E>) ListN.EMPTY_LIST;
|
||||
|
|
|
@ -1057,12 +1057,7 @@ public interface List<E> extends Collection<E> {
|
|||
* @throws NullPointerException if coll is null, or if it contains any nulls
|
||||
* @since 10
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <E> List<E> copyOf(Collection<? extends E> coll) {
|
||||
if (coll instanceof ImmutableCollections.AbstractImmutableList) {
|
||||
return (List<E>)coll;
|
||||
} else {
|
||||
return (List<E>)List.of(coll.toArray());
|
||||
}
|
||||
return ImmutableCollections.listCopy(coll);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue