Forcing `SingleTask` implementors to also extend `AbstractList` isn't very elegant, and default methods aren't meant to be used to define trait-like entities, which your `SingleTask` interface looks like.*
Bearing all that in mind the simplest solution is probably this:
public abstract class SingleTask extends AbstractList<Runnable> implements Runnable {
@Override
public final Runnable get(final int x) {
if (x != 0) {
throw new IndexOutOfBoundsException();
}
return this;
}
@Override
public final int size() {
return 1;
}
@Override
public abstract void run();
}
*There are several reasons why default methods-as-traits is a bad idea, the most obvious one being that any implementor can simply override your default method, ruining your trait.