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

  • Home
  • SEARCH
  • 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 4070522
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:38:18+00:00 2026-05-20T16:38:18+00:00

I have an abstract class that has a generic method and I want to

  • 0

I have an abstract class that has a generic method and I want to override the generic method by substituting specific types for the generic parameter. So in pseudo-code I have the following:

public abstract class GetAndParse {
  public SomeClass var;

  public abstract <T extends AnotherClass> void getAndParse(T... args);
}

public class Implementor extends GetAndParse {
  // some field declarations

  // some method declarations

  @Override
  public <SpecificClass> void getAndParse(SpecificClass... args) {
    // method body making use of args
  }
}

But for some reason I’m not allowed to do this? Am I making some kind of syntax error or is this kind of inheritance and overriding not allowed? Specifically I’m getting an error about @Override because the eclipse IDE keeps reminding me to implement getAndParse.

Here’s how I want the above code to work. Somewhere else in my code there is a method that expects instances of objects that implement GetAndParse which specifically means that they have a getAndParse method that I can use. When I call getAndParse on that instance the compiler checks to see whether I have used specific instances of T in the proper way, so in particular T should extend AnotherClass and it should be SpecificClass.

  • 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-05-20T16:38:19+00:00Added an answer on May 20, 2026 at 4:38 pm

    What we are having here is two different methods with individual type parameters each.

    public abstract <T extends AnotherClass> void getAndParse(Args... args);
    

    This is a method with a type parameter named T, and bounded by AnotherClass, meaning each subtype of AnotherClass is allowed as a type parameter.

    public <SpecificClass> void getAndParse(Args... args)
    

    This is a method with a type parameter named SpecificClass, bounded by Object (meaning each type is allowed as a type parameter). Do you really want this?

    Is the type parameter used inside Args? I think the problem would be there.


    The meaning of

    public abstract <T extends AnotherClass> void getAndParse(T... args);
    

    is that the caller of the method can decide with which type parameter he wants to call the method, as long as this is some subtype of AnotherClass. This means that in effect the method can be called with any objects of type AnotherClass.

    Since the caller can decide the type parameter, you can’t in a subclass narrow down the parameter type to SpecificClass – this would not be an implementation of the method, but another method with same name (overloading).

    Maybe you want something like this:

    public abstract class GetAndParse<T extends AnotherClass> {
      public SomeClass var;
    
      public abstract void getAndParse(T... args);
    }
    
    public class Implementor extends GetAndParse<SpecificClass> {
      // some field declarations
    
      // some method declarations
    
      @Override
      public void getAndParse(SpecificClass... args) {
        // method body making use of args
      }
    }
    

    Now the getAndParse method implements the parent class’ method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a abstract generic class. I want to define a method inside there
I have an abstract class that has a shared method which creates a new
I have a abstract Parent class that has multiple children. I'd like the child
I have a base abstract logger class, that has an instance variable that I
Ok so I have an abstract base class called Product, a KitItem class that
If I have a base class such that public abstract class XMLSubscription <T extends
I have a collection of classes that inherit from an abstract class I created.
I have an abstract class defining a pure virtual method in c++: class Base
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
I have a question regarding the following code: abstract class a { public static

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.