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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:10:47+00:00 2026-05-22T12:10:47+00:00

I didn’t manage to compile a set of classes with nested interfaces. Let’s assume

  • 0

I didn’t manage to compile a set of classes with nested interfaces.

Let’s assume there are two interfaces:

public interface IntA
{   
    public Map<String, ? extends IntB> getName();
    public void setName(Map<String, ? extends IntB> name);
}

public interface IntB
{
    long getId();
    void setId(long id);
}

and two corresponding implementation classes

public class ImplA implements IntA,Serializable
{
    private Map<String, ImplB> name;
    public Map<String, ? extends IntB> getName(){return name;}
    public void setName(Map<String, ? extends IntB> name)
                  {this.name = (Map<String, ImplB>)name;}
}

public class ImplB implements IntB,Serializable
{
    private long id;
    public long getId() {return id;}
    public void setId(long id) {this.id = id;}
}

How can i use the setter of ImplA?

public static void create(Random rnd, String code)
{
  ImplB b = new ImplB();
  b.setId(1);

  ImplA a = new ImplA();
  a.getName().put("key", b);
  a.getName().put("key", (IntB)b);
}

results in:

put(java.lang.String,capture#50 of ? extends IntB) in
java.util.Map<java.lang.String,capture#50 of ? extends .IntB>
cannot be applied to (java.lang.String,ImplB)

put(java.lang.String,capture#845 of ? extends IntB) in
java.util.Map<java.lang.String,capture#845 of ? extends IntB>
cannot be applied to (java.lang.String,IntB)

Thank you

Thor

  • 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-22T12:10:48+00:00Added an answer on May 22, 2026 at 12:10 pm

    Your getter is returning a more general type. Imagine if it the actual return value was a reference to a Map<String, SomeOtherImplB> – you wouldn’t want to be able to put an ImplB there.

    If you want to be able to put a value into a Map, you either need the value type to be specified exactly, or specified with a “super” constraint rather than an “extends” constraint. For example:

    // This is fine
    Map<String, ? super Apple> map = getMapFromSomewhere();
    map.put("Foo", new Apple());
    
    // This isn't - it might be a Map<String, Orange>!
    Map<String, ? extends Fruit> map = getMapFromSomewhere();
    map.put("Foo", new Apple());
    

    So that’s why it’s not working at the moment. As for the right way to work around that… it’s hard to know exactly what you’re trying to do. Maybe you want to change it to:

    public interface IntA
    {   
        public Map<String, IntB> getName();
        public void setName(Map<String, IntB> name);
    }
    

    … or the alternative is to make IntA generic:

    public interface IntA<T extends IntB> 
    {   
        public Map<String, T> getName();
        public void setName(Map<String, T> name);
    }
    

    So in this case, your ImplA class would implement IntA<ImplB>.

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

Sidebar

Related Questions

I didn't fully understand the concept of threads I have some questions. Assume we
I didn't manage to find any functionalities for minimizing/maximizing programatically. I want to minimize
I didn'y manage to query a web service from android emulator (previously I had
I didn't see anything on here about it with a quick search, if there
Didn't see a question similar to this, so here goes: Let's say I'm running
I didn't set the username on my development computer and made a few commits.
Didn't find any from their website. I mostly just trying to see which one
I didn't get the answer to this anywhere. What is the runtime complexity of
I didn't see any similar questions asked on this topic, and I had to
I didn't see the option to point the workspace (or it's VS equivalent, I'm

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.