Suppose I have this two interfaces...
public interface ObjectInterface { /* empty interface */ }
public interface ObjectHandler
{
void handle(ObjectInterface object);
}
...and also a concrete class which implements the ObjectInterface:
public class ConcreteObject implements ObjectInterface { /* ... */ }
Why is this not allowed in Java?
public class ConcreteHandler implements ObjectHandler
{
@Override
public void handle(ConcreteObject object) // <-- ObjectInterface implementation
{
// ...
}
}
A ConcreteObject implements the ObjectInterface interface afterall.
However, is there a way to design my classes in Java keeping this pattern of abstraction?
ConcreteHandler#handlesince it only acceptsConcreteObjectand not the broader typeObjectInterface. So it fails to correctly implement theObjectHandlerinterface.