When I see the Iterable interface source, it looks like the foreach method and Spliterator methods are not abstract. How an interface can have non abstract methods? Or is there anything I am missing in this? See the Iterbale interface source below.
package java.lang; import java.util.Iterator; import java.util.Objects; import java.util.Spliterator; import java.util.Spliterators; import java.util.function.Consumer; public abstract interface Iterable<T> { public abstract Iterator<T> iterator(); public void forEach(Consumer<? super T> paramConsumer) { Objects.requireNonNull(paramConsumer); Iterator localIterator = iterator(); while (localIterator.hasNext()) { Object localObject = localIterator.next(); paramConsumer.accept(localObject); } } public Spliterator<T> spliterator() { return Spliterators.spliteratorUnknownSize(iterator(), 0); } } /* Location: C:\Program Files\Java\jre1.8.0_121\lib\rt.jar * Qualified Name: java.lang.Iterable * Java Class Version: 8 (52.0) * JD-Core Version: 0.7.1 */
forEachshould be declared asdefault. And why is it declared asabstract interface? What version are you looking at?