Last active
December 14, 2015 08:19
-
-
Save dlhartveld/5056918 to your computer and use it in GitHub Desktop.
JDK8 example: implementing an empty Iterable<Object> (functional interface with default method) with a lambda expression.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface java.lang.Iterable<T> { | |
abstract Iterator<T> iterator(); | |
default void forEach(Consumer<? super T> consumer) { | |
for (T t : this) { | |
consumer.accept(t); | |
} | |
} | |
} | |
java.lang.Iterable<Object> i = () -> java.util.Collection.emptyList().iterator(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment