Skip to content

Commit

Permalink
Move EMPTY to RegularImmutableList.
Browse files Browse the repository at this point in the history
This was requested in #1977 to avoid circular static-init dependencies.
I fear that we have other such problems. We should consider adding a test for them.
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=88131198
  • Loading branch information
cpovirk authored and cgdecker committed Mar 16, 2015
1 parent 1839378 commit f3099c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 3 additions & 6 deletions guava/src/com/google/common/collect/ImmutableList.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.common.base.Preconditions.checkPositionIndexes;
import static com.google.common.collect.ObjectArrays.arraysCopyOf;
import static com.google.common.collect.ObjectArrays.checkElementsNotNull;
import static com.google.common.collect.RegularImmutableList.EMPTY;

import com.google.common.annotations.GwtCompatible;

Expand Down Expand Up @@ -62,10 +63,6 @@
@SuppressWarnings("serial") // we're overriding default serialization
public abstract class ImmutableList<E> extends ImmutableCollection<E>
implements List<E>, RandomAccess {

private static final ImmutableList<Object> EMPTY =
new RegularImmutableList<Object>(ObjectArrays.EMPTY_ARRAY);

/**
* Returns the empty immutable list. This set behaves and performs comparably
* to {@link Collections#emptyList}, and is preferable mainly for consistency
Expand Down Expand Up @@ -400,8 +397,8 @@ ImmutableList<E> subListUnchecked(int fromIndex, int toIndex) {
}

class SubList extends ImmutableList<E> {
transient final int offset;
transient final int length;
final transient int offset;
final transient int length;

SubList(int offset, int length) {
this.offset = offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import javax.annotation.Nullable;

/**
* Implementation of {@link ImmutableList} with one or more elements.
* Implementation of {@link ImmutableList} used for 0 or 2+ elements (not 1).
*
* @author Kevin Bourrillion
*/
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // uses writeReplace(), not default serialization
class RegularImmutableList<E> extends ImmutableList<E> {
static final ImmutableList<Object> EMPTY =
new RegularImmutableList<Object>(ObjectArrays.EMPTY_ARRAY);

private final transient int offset;
private final transient int size;
private final transient Object[] array;
Expand Down

0 comments on commit f3099c7

Please sign in to comment.