I have an interface and a class implementing the interface like this:
public interface DocumentDAO<T>{
public long insert (T doc);
}
public class PostgreSQLDocumentDAO implements DocumentDAO<Document>{
public long insert(Document doc){}
protected void insertDocument(Document doc){}
}
I want to override the insert method of PostgreSQLDocumentDAO changing the parameter from Document to Page, where Page is a class that extends Document.
I want something like this:
public class PostgreSQLPageDAO extends PostgreSQLDocumentDAO{
public long insert(Page doc){
super.insertDocument(page);
//specific implementation goes here
}
}
How I can get this?
UPDATE: The code above isn’t right because a class called Inserter uses the interface DocumentDAO. When it calls the insert method, even if is a PostgreSQLPageDAO object, it will call the insert method to insert Document because this method is inherited.
I want to do a way to when the Inserterclass call the insert method, it uses the method that inserts the page. In this way, I think I need override the insert (Document doc) from PostgreSQLDocumentDAO.
Two options here.
Then you change it to
and
2.You cannot modify PostgreSQLDocumentDAO
Then you need to overload and override the insert method in PostgreSQLPageDAO with: