Here is a simplified example showing my problem:
import java.util.List;
public interface SingleTask extends List<Runnable>, Runnable {
default Runnable get(final int x) {
if (x != 0) {
throw new IndexOutOfBoundsException();
}
return this;
}
default int size() {
return 1;
}
}
import java.util.AbstractList;
public class MyTask extends AbstractList<Runnable> implements SingleTask {
@Override
public void run() {
System.out.println("hello");
}
}
In SingleTask
I provide implementations for the methods get
and size
, which are the only abstract methods from AbstractList
. However, when I compile MyTask
, I still get errors like:
The type MyTask must implement the inherited abstract method AbstractCollection.size()
or
MyTask.java:3: error: MyTask is not abstract and does not override abstract method get(int) in AbstractList
(depending on the compiler). I am, of course, using java 8.
So I have two questions:
- Why am I getting these errors? I was expecting it to recognize the default implementations.
- If it's not supposed to work like that, then what's the simplest way to use those two methods in
MyTask
without copying the whole code?