I'm trying to write a library of collection interfaces that implement most of the methods in the standard Collection API using the new default method syntax in Java 8. Here's a small sample of what I'm going for:
public interface MyCollection<E> extends Collection<E> {
@Override default boolean isEmpty() {
return !iterator().hasNext();
}
//provide more default overrides below...
}
public interface MyList<E> extends MyCollection<E>, List<E> {
@Override default Iterator<E>iterator(){
return listIterator();
}
//provide more list-specific default overrides below...
}
However, even this simple example is met with a compiler error:
error: interface MyList<E> inherits abstract and default
for isEmpty() from types MyCollection and List
From my understanding of default methods, this should be allowed since only one of the extended interfaces provides a default implementation, but apparently that's not the case. What's going on here? Is there a way to get this to do what I want?