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 6934933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:01:41+00:00 2026-05-27T12:01:41+00:00

I have a method (that I can’t change, it belongs to a different project)

  • 0

I have a method (that I can’t change, it belongs to a different project) defined in an interface that limits the input classes using generics to a Class that extends a Class (which in turn implements an interface), like this:

<P extends ParentInterface, E extends P> void register(Class<E> cl, Class<P> parent);

This works fine when you’re calling it normally, but in order to make it easier to register a potentially large number of classes this way (and unregister the same set when needed) I was hoping to store them in a Map<Class<? extends ParentInterface>, Class<? extends ParentInterface>> (or similar) and loop over it when registering/unregistering. Unfortunately this – predictably – leads to compile time errors saying bound mismatch:

Bound mismatch: The generic method register(Class<E>, Class<P>) is not applicable for the arguments (Class<capture#5-of ? extends ParentInterface, Class<capture#13-of ? extends ParentInterface>). The inferred type capture#5-of ? extends ParentInterface is not a valid substitute for the bounded parameter <E extends P>

Can I get around this in some way, or am I stuck doing individual calls and making sure I’m keeping the register and unregister calls synchronized?

  • 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-27T12:01:42+00:00Added an answer on May 27, 2026 at 12:01 pm

    does it help to make the class generic, that will EDIT not encapsulate but extends the Map interface?

    public class TestMap <P extends ParentInterface, E extends P> extends HashMap implements Map {
        void registerall(){
            Class<E> key = (Class<E>) this.keySet().iterator().next();
            Class<P> val = (Class<P>) this.get(key);
            register(key, val);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw DatabaseErrorHandler interface that have onCorruption method , this interface can be passed
I have created a method that can be called using a stored procedure name
I have a method that can return either a single object or a collection
I have class method that returns a list of employees that I can iterate
Let's say you have a business logic method that can perform some operation across
I have a method that will receive a string , but before I can
Let's say I have a subroutine/method that a user can call to test some
i have a javascript method that takes a date: convert(new Date(02/20/2010); how can i
I can't figure out why this is. I have a connect method that works
I have a Rails controller action to test. In that action, a method User.can?

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.