Reputation: 141
I'm trying to place an array of objects and its equivalent id inside a HashMap.
This is my HashMap:
private Map<String, Value[]> array_memory = new HashMap<String, Value[]>();
This my array of objects:
Value[] array = new Value[x];
And this is how I'm putting them inside array_memory:
return array_memory.put(id, array);
However, when I run my program I'm getting this error:
error: incompatible types: Value[] cannot be converted to Value
return array_memory.put(id, array);
^
Any help would be highly appreciated. (I would like to apologize if I'm missing something obvious, I've been working on this for hours now and I'm not in my best condition).
Thank you for your time!
Upvotes: 0
Views: 139
Reputation: 3707
It look fine with the code snippet you provided.
I think that the variable receiving your returned array_memory.put(id, array)
is of type Value
instead of Value[]
Upvotes: 1
Reputation: 1858
The put Function returns the second parameter, maybe you get your type missmatch in the return.
Upvotes: 0
Reputation: 5459
I assume this takes place inside a method with a return type of Value
. The compiler complains about this because map#put
returns the value being added, leading to this error because a Value[]
can't be converted to a Value
.
Upvotes: 5