1

As of Java 9, Iterable is defined as the following (without documentation, for brevity):

public interface Iterable<T> {
    Iterator<T> iterator();

    default void forEach(Consumer<? super T> action) {
        Objects.requireNonNull(action);
        for (T t : this) {
            action.accept(t);
        }
    }

    default Spliterator<T> spliterator() {
        return Spliterators.spliteratorUnknownSize(iterator(), 0);
    }
}

As we can see, this interface only contains one abstract method. Because one or more of the methods in this interface utilize the default keyword, this interface must have been edited since the release of Java 8 (the documentation defines @since 1.8, but was not included in this question).

For those reasons, why is Iterable not defined with the @FunctionalInterface annotation?

Naman
  • 27,789
  • 26
  • 218
  • 353
Jacob G.
  • 28,856
  • 5
  • 62
  • 116
  • It seems to me having one abstract method is a necessary but not sufficient requirement for annotation with `@FunctionalInterface`. Or can you think of a good use case where `forEach` would serve in a lambda expression (as opposed to receiving a lambda expression as argument)? – rookie09 Nov 10 '17 at 16:02
  • 1
    This looks exactly like the Java 8 release version. Why do you think it “must have been edited since the release of Java 8”? – Holger Nov 10 '17 at 17:33
  • @Holger I meant to say that it was edited with Java 8 – Jacob G. Nov 10 '17 at 17:34
  • 1
    Ok, that makes more sense. You may replace “since” with “for” or “with”… – Holger Nov 10 '17 at 17:34

0 Answers0