Here's the code I essentially want, which won't compile:
interface Interface {
interface ArgumentInterface {
// Some methods
}
void doCallback(Consumer<? super ArgumentInterface> callback);
}
interface SubInterface extends Interface {
interface ArgumentSubInterface extends ArgumentInterface {
// Some more methods
}
@Override
void doCallback(Consumer<? super ArgumentSubInterface> callback);
}
The idea here is that Interface will pass an instance of ArgumentInterface to the Consumer that the user provides, while SubInterface will pass an instance of the more specific ArgumentSubInterface. In particular, I want the user to be able to pass a Consumer<ArgumentSubInterface> to SubInterface.doCallback() and have that work.
Naively, it seems like this should work as-written: Any argument that is accepted by Interface's version will also be accepted by SubInterface's version. However, Java claims that the method doesn't override.