diff options
Diffstat (limited to 'guava/src/com/google/common/collect/ImmutableList.java')
-rw-r--r-- | guava/src/com/google/common/collect/ImmutableList.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/guava/src/com/google/common/collect/ImmutableList.java b/guava/src/com/google/common/collect/ImmutableList.java index 9c60caf3f..7c7801dbc 100644 --- a/guava/src/com/google/common/collect/ImmutableList.java +++ b/guava/src/com/google/common/collect/ImmutableList.java @@ -26,6 +26,7 @@ import static com.google.common.collect.RegularImmutableList.EMPTY; import static java.util.Objects.requireNonNull; import com.google.common.annotations.GwtCompatible; +import com.google.common.annotations.GwtIncompatible; import com.google.common.annotations.J2ktIncompatible; import com.google.common.annotations.VisibleForTesting; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -444,6 +445,12 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> * Returns an immutable list of the elements between the specified {@code fromIndex}, inclusive, * and {@code toIndex}, exclusive. (If {@code fromIndex} and {@code toIndex} are equal, the empty * immutable list is returned.) + * + * <p><b>Note:</b> in almost all circumstances, the returned {@link ImmutableList} retains a + * strong reference to {@code this}, which may prevent the original list from being garbage + * collected. If you want the original list to be eligible for garbage collection, you should + * create and use a copy of the sub list (e.g., {@code + * ImmutableList.copyOf(originalList.subList(...))}). */ @Override public ImmutableList<E> subList(int fromIndex, int toIndex) { @@ -498,6 +505,15 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> boolean isPartialView() { return true; } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } /** @@ -678,6 +694,15 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> boolean isPartialView() { return forwardList.isPartialView(); } + + // redeclare to help optimizers with b/310253115 + @SuppressWarnings("RedundantOverride") + @Override + @J2ktIncompatible // serialization + @GwtIncompatible // serialization + Object writeReplace() { + return super.writeReplace(); + } } @Override @@ -724,6 +749,7 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> @Override @J2ktIncompatible // serialization + @GwtIncompatible // serialization Object writeReplace() { return new SerializedForm(toArray()); } @@ -901,4 +927,6 @@ public abstract class ImmutableList<E> extends ImmutableCollection<E> return asImmutableList(contents, size); } } + + private static final long serialVersionUID = 0xcafebabe; } |