diff --git a/android/guava/src/com/google/common/collect/Iterators.java b/android/guava/src/com/google/common/collect/Iterators.java index 9f7b6f711295..0553f37dea4c 100644 --- a/android/guava/src/com/google/common/collect/Iterators.java +++ b/android/guava/src/com/google/common/collect/Iterators.java @@ -1105,30 +1105,26 @@ protected T get(int index) { private static final class SingletonIterator extends UnmodifiableIterator { - private static final Object SENTINEL = new Object(); - - private @Nullable Object valueOrSentinel; + private final T value; + private boolean done; SingletonIterator(T value) { - this.valueOrSentinel = value; + this.value = value; } @Override public boolean hasNext() { - return valueOrSentinel != SENTINEL; + return !done; } @Override @ParametricNullness public T next() { - if (valueOrSentinel == SENTINEL) { + if (done) { throw new NoSuchElementException(); } - // The field held either a T or SENTINEL, and it turned out not to be SENTINEL. - @SuppressWarnings("unchecked") - T t = (T) valueOrSentinel; - valueOrSentinel = SENTINEL; - return t; + done = true; + return value; } } diff --git a/guava/src/com/google/common/collect/Iterators.java b/guava/src/com/google/common/collect/Iterators.java index 9f7b6f711295..0553f37dea4c 100644 --- a/guava/src/com/google/common/collect/Iterators.java +++ b/guava/src/com/google/common/collect/Iterators.java @@ -1105,30 +1105,26 @@ protected T get(int index) { private static final class SingletonIterator extends UnmodifiableIterator { - private static final Object SENTINEL = new Object(); - - private @Nullable Object valueOrSentinel; + private final T value; + private boolean done; SingletonIterator(T value) { - this.valueOrSentinel = value; + this.value = value; } @Override public boolean hasNext() { - return valueOrSentinel != SENTINEL; + return !done; } @Override @ParametricNullness public T next() { - if (valueOrSentinel == SENTINEL) { + if (done) { throw new NoSuchElementException(); } - // The field held either a T or SENTINEL, and it turned out not to be SENTINEL. - @SuppressWarnings("unchecked") - T t = (T) valueOrSentinel; - valueOrSentinel = SENTINEL; - return t; + done = true; + return value; } }