Skip to content

Instantly share code, notes, and snippets.

@dlhartveld
Last active December 14, 2015 08:19
Show Gist options
  • Save dlhartveld/5056918 to your computer and use it in GitHub Desktop.
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.
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