< prev index next >
src/java.base/share/classes/java/lang/Iterable.java
Print this page
@@ -20,17 +20,17 @@
*
* 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;
+package javany.lang;
-import java.util.Iterator;
+import javany.util.Iterator;
import java.util.Objects;
-import java.util.Spliterator;
-import java.util.Spliterators;
-import java.util.function.Consumer;
+//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,11 +40,11 @@
* @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> {
+public interface Iterable<any T> {
/**
* Returns an iterator over elements of type {@code T}.
*
* @return an Iterator.
*/
@@ -69,12 +69,16 @@
* @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);
+// 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,9 +99,9 @@
*
* @return a {@code Spliterator} over the elements described by this
* {@code Iterable}.
* @since 1.8
*/
- default Spliterator<T> spliterator() {
- return Spliterators.spliteratorUnknownSize(iterator(), 0);
- }
+// default Spliterator<T> spliterator() {
+// return Spliterators.spliteratorUnknownSize(iterator(), 0);
+// }
}
< prev index next >