diff --git a/wire-runtime/src/main/java/com/squareup/wire/internal/ImmutableList.java b/wire-runtime/src/main/java/com/squareup/wire/internal/ImmutableList.java index 5974c247a2..9fe497d50f 100644 --- a/wire-runtime/src/main/java/com/squareup/wire/internal/ImmutableList.java +++ b/wire-runtime/src/main/java/com/squareup/wire/internal/ImmutableList.java @@ -24,7 +24,7 @@ import java.util.RandomAccess; final class ImmutableList extends AbstractList implements RandomAccess, Serializable { - final List list; + private final ArrayList list; ImmutableList(List list) { this.list = new ArrayList<>(list); @@ -38,6 +38,10 @@ final class ImmutableList extends AbstractList implements RandomAccess, Se return list.get(i); } + @Override public Object[] toArray() { + return list.toArray(); // Optimizing for mutable copy by MutableOnWriteList. + } + private Object writeReplace() throws ObjectStreamException { return Collections.unmodifiableList(list); }