[java] Using an instance of an object as a key in hashmap, and then access it with exactly new object?

I have a hasmap with a key object,

HashMap<Key, Object> test;

and make new Key("the same") as key..

so its like..:

test.put(new Key("the same"), someObject);

(without storing that key in a variable)

so.. after a while... i want to access the hashmap, because i do not have the object, i've tried to make new Key("the same") and make it as a key. But it didnt work.

How to make it work? (without saving the first object "key" in a variable)

So meanwhile, for now, im using String object as a key.

HashMap<String, Object>

This question is related to java hashmap

The answer is