Class EmptyIterable<E>

  • Type Parameters:
    E - the type of elements returned by the iterator
    All Implemented Interfaces:
    java.lang.Iterable<E>

    @Immutable
    public class EmptyIterable<E>
    extends IterableAdapter<E>
    An empty Iterable implementation that always returns an empty iterator.

    This class is a singleton-friendly extension of IterableAdapter, primarily useful for representing an empty collection view. It guarantees that the method IterableAdapter.iterator() will return an instance of EmptyIterator.INSTANCE, ensuring consistent behavior across uses.

    Example Usage

    
     Iterable<String> emptyIterable = EmptyIterable.INSTANCE;
     for (String item : emptyIterable) {
         // This loop will not execute as the iterable is empty.
     }
     
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    Iterable, EmptyIterator
    • Constructor Summary

      Constructors 
      Constructor Description
      EmptyIterable()  
    • Method Summary

      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • EmptyIterable

        public EmptyIterable()