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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:51:07+00:00 2026-06-15T17:51:07+00:00

I have a variable that has several upper bounded wildcards, like so: private Map<

  • 0

I have a variable that has several upper bounded wildcards, like so:

private Map< Class< ? extends MyClass1 >, List< ? extends MyClass2< ? extends MyClass3, ? extends  MyClass1> > > _variableName;

Is there any way to enforce that the bound value ? extends MyClass1 be the same for the Type of the Class class and the 2nd param of the MyClass2 class?

  • 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-15T17:51:08+00:00Added an answer on June 15, 2026 at 5:51 pm

    Yes:

        public class Foo<T extends MyClass1> {
            private Map< Class<T>, List<? extends MyClass2<? extends MyClass3, T>>> bar;
            ...
        }
    

    You could also do this with a generic method. It depends on where you want to make the guarantee (and by extension, where the Map is instantiated), when defining the class or when calling a method that instantiates this Map.

    UPDATE:

    In response to the (correct) observation that this map will only contain one element, perhaps the questioner had this in mind instead:

        public class Foo {
            private Map<Class<? extends MyClass1>, List<? extends MyClass2<? extends MyClass3, ? extends MyClass1>>> bar;
    
            public <T extends MyClass1> void add(Class<T> myClass, List<? extends MyClass2<? extends MyClass3, T>>> myList) {
                bar.put(myClass, myList);
            }
    
            ...
        }
    

    Assuming this is the only way to add elements to your private map, then that ensures the types always match.

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

Sidebar

Related Questions

I have a Class that has a private variable with a public setter/getter function:
I have a class that has a vector member variable, which I fill up
I have a custom class that has as an instance variable of a coordinate:
So I have a main class and another class that has a variable I
I have a class with a static std::map member variable that maps char s
I have a class Foo which has several methods like button_0_0 , button_0_1 ,
I have an object variable that has several properties. MyVar = {prop1 : 0,
I have a variable that has this string: <DIV><SPAN style=FONT-FAMILY: Tahoma; FONT-SIZE: 10pt>[If the
I have program that has a variable that should never change. However, somehow, it
Say I have an instance variable MyObject that has been allocated and initialized. Then

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.