Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7742145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:12:31+00:00 2026-06-01T09:12:31+00:00

I have an interface and a class implementing the interface like this: public interface

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:12:33+00:00Added an answer on June 1, 2026 at 9:12 am

    Two options here.

    1. You can modify PostgreSQLDocumentDAO

    Then you change it to

    public class PostgreSQLDocumentDAO<D extends Document> implements DocumentDAO<D>
    

    and

    public class PostgreSQLPageDAO extends PostgreSQLDocumentDAO<Page>
    

    2.You cannot modify PostgreSQLDocumentDAO

    Then you need to overload and override the insert method in PostgreSQLPageDAO with:

    // Override
    @Override
    public long insert(Document doc){
        if (!(doc instanceof Page))
             throw new IlegalArgumentException("insert only accepts Page");
        super.insert(doc);
    }
    
    // Overload
    public long insert(Page page){
        super.insert(page);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have an interface like this: public interface ISomeInterface { ... } I
If we have: public interface Foo{} public class Bar implements Foo{...} Is there a
I have crated an interface like this public interface NetworkInterface { public void onReceive();
I have this interface and a class implementing it: interface Scraper { string DateToUrl(DateTime
I have some classes that look like this: MODEL public abstract class BaseEntity<O extends
in my Silverlight 4 project, I have a simple class implementing the interface like:
I have a generic PostProcessor interface that looks like this: public interface PostProcessor<T> {
I have an interface defining a method like this : public List<IA> myMethod(); with
I have an interface with several events I have base class implementing the interface
Say I have a parent interface/class like so interface Parent<T> {} And a number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.