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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:13:12+00:00 2026-06-14T09:13:12+00:00

Possible Duplicate: Is `List<Dog>` a subclass of `List<Animal>`? Why aren’t Java’s generics implicitly polymorphic?

  • 0

Possible Duplicate:
Is `List<Dog>` a subclass of `List<Animal>`? Why aren’t Java’s generics implicitly polymorphic?

I need help understanding whats going on.

I have an interface

public interface Foo {

  Map<String, ParameterValue> getParameters();
}

public interface ParameterValue { }

And an implementation of Foo.

class FooImpl implements Foo {
   Map<String, ParameterValueImpl> parameters = new HashMap<String, ParameterValueImpl>();
   //ParameterValueImpl an implementation of ParameterValue

@Override
    public Map<String, ParameterValue> getParameters() {
        return ((Map<String,ParameterValue>) parameters);
    }   

}

I get the following error

[ERROR] Failed to execute goal
failure [ERROR]
src/main/java/domainJPA/model/FooImpl.java:[92,45]
inconvertible types [ERROR] found   :
java.util.Map<java.lang.String,domainJPA.model.ParameterValueImpl>
[ERROR] required:
java.util.Map<java.lang.String,domain.model.ParameterValue>

I have to use the ParameterValue in the interface of Foo, and in FooImpl I must just the implementation of ParameterValue (ParameterValueImpl) because its an @Entity and jpa requires it.

How can I make this code compile?

EDIT

If I change the code to ? extends ParameterValue as suggested in one of the answers, then I cannot use the Foo interface.

The following code results in compilation error: The method put(String, capture#8-of ? extends ParameterValue) in the type Map<String,capture#8-of ? extends ParameterValue> is not applicable for the arguments (String, ParameterValueImpl)

foo.getParameters().put("test", new ParameterValueImpl);

  • 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-14T09:13:14+00:00Added an answer on June 14, 2026 at 9:13 am

    Think about it — if the return value from getParameters() is actually a Map<String, ParameterValueImpl>, then you have the ability to add a value to the map that derives from ParameterValue, but not ParameterValueImpl. You would be breaking type safety by doing that.

    You have two options to correct this:

    1. In getParameters(), copy the map into a new map of the correct type.
    2. Use Map<String, ParameterValue> as the type for FooImpl.parameters.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is List<Dog> a subclass of List<Animal>? Why aren't Java's generics implicitly polymorphic?
Possible Duplicate: Is List<Dog> a subclass of List<Animal> ? Why aren't Java's generics implicitly
Possible Duplicate: Is List&lt;Dog&gt; a subclass of List&lt;Animal&gt; ? Why aren't Java's generics implicitly
Possible Duplicate: How to convert List<Integer> to int[] in Java? I have an ArrayList
Possible Duplicate: Type List vs type ArrayList in Java Why is it recommended to
Possible Duplicate: Java - Distinct List of Objects i have a sorted array of
Possible Duplicate: Generate list of all possible permutations of a string I need to
Possible Duplicate: When to use a List over an Array in Java? As the
Possible Duplicate: Implement linked list in php We can make link list in Java,
Possible Duplicate: List all svn:externals recursively? I need to move the location of a

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.