< prev index next >

src/java.base/share/classes/java/lang/Iterable.java

Print this page

        

*** 20,36 **** * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package java.lang; ! import java.util.Iterator; import java.util.Objects; ! import java.util.Spliterator; ! import java.util.Spliterators; ! import java.util.function.Consumer; /** * Implementing this interface allows an object to be the target of * the "for-each loop" statement. See * <strong> --- 20,36 ---- * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ ! package javany.lang; ! import javany.util.Iterator; import java.util.Objects; ! //import java.util.Spliterator; ! //import java.util.Spliterators; ! import javany.util.function.Consumer; /** * Implementing this interface allows an object to be the target of * the "for-each loop" statement. See * <strong>
*** 40,50 **** * @param <T> the type of elements returned by the iterator * * @since 1.5 * @jls 14.14.2 The enhanced for statement */ ! public interface Iterable<T> { /** * Returns an iterator over elements of type {@code T}. * * @return an Iterator. */ --- 40,50 ---- * @param <T> the type of elements returned by the iterator * * @since 1.5 * @jls 14.14.2 The enhanced for statement */ ! public interface Iterable<any T> { /** * Returns an iterator over elements of type {@code T}. * * @return an Iterator. */
*** 69,80 **** * @throws NullPointerException if the specified action is null * @since 1.8 */ default void forEach(Consumer<? super T> action) { Objects.requireNonNull(action); ! for (T t : this) { ! action.accept(t); } } /** * Creates a {@link Spliterator} over the elements described by this --- 69,84 ---- * @throws NullPointerException if the specified action is null * @since 1.8 */ default void forEach(Consumer<? super T> action) { Objects.requireNonNull(action); ! // for (T t : this) { ! // action.accept(t); ! // } ! Iterator<T> iterator = iterator(); ! while (iterator.hasNext()) { ! action.accept(iterator.next()); } } /** * Creates a {@link Spliterator} over the elements described by this
*** 95,103 **** * * @return a {@code Spliterator} over the elements described by this * {@code Iterable}. * @since 1.8 */ ! default Spliterator<T> spliterator() { ! return Spliterators.spliteratorUnknownSize(iterator(), 0); ! } } --- 99,107 ---- * * @return a {@code Spliterator} over the elements described by this * {@code Iterable}. * @since 1.8 */ ! // default Spliterator<T> spliterator() { ! // return Spliterators.spliteratorUnknownSize(iterator(), 0); ! // } }
< prev index next >