0
votes

Hello I want to add a field in HashMap but I have an error

"java: incompatible types: inference variable T has incompatible bounds equality constraints: java.util.Map<java.lang.String,java.lang.Object>lower bounds: java.lang.Object" and I don't see why ?

metadataMap.put(review.getField(), metadataMap.get(review.getField()).stream()
                            .filter(suggestion -> review.getTerm() != null && review.getTerm().equals(suggestion.get(Constants.Review.TERM)))
                            .map(termInfo -> termInfo.put(Constants.STATUS, review.getStatus()))
                            .collect(Collectors.toList()));

Here is the other intel about my code

private void removeReviewFromSuggestionsOrDetails(ContainerModel container, ReviewModel review, String field, String instance)
        throws ApiException {
    Map<String, List<Map<String, Object>>> metadataMap = (Map<String, List<Map<String, Object>>>) container.get(field);

Should I use map there or something else? For add my new field Status

1
This question has been answered elsewhere on SO. See e.g. [stackoverflow.com/questions/27522741/… and [stackoverflow.com/questions/41719097/…. Apart from that you should seriously consider if a Map<String, List<Map<String, Object>>> is the type you want to work with.Hintham

1 Answers

0
votes

Looking at such a small sample of code, I cannot reproduce the problem here and be sure of my solution.

However, I would suggest you to look at your "Types".

At your "removeReviewFromSuggestionsOrDetails" function:

Map<String, List<Map<String, Object>>> metadataMap = 

When declaring this, you are saying:

-this is a Map that receives Strings as Keys

-and receives a List of Maps as Values

Therefore, to proper use the method "put(Key, Values)" you should match the types your Map will recive with the types you use as arguments in the method.

What should be done is:

metadataMap.put(Keys, Values) should be metadataMap.put(String, List<Map<String, Object>>)

What you are doing is:

metadataMap.put(String, Map<String, List<Map<String, Object>>>)

Do you see the problem now? You are giving the put() method a String as Key and a Map as Value.

However, you declared your metadataMap to receive a String as Key and a List of Maps as Value.

I suppose this will fix your problem.