I have a question about HashMaps. We are writing a small-c(-ish) compiler and for that we are using a symbol table. We are implementing this using a hashmap.
Now to take scopes into account we use a stack. So everytime we enter a new scope we push a token that signifies this on the stack. We then put all the keys from the hashmap on the stack for all the symbols we encounter. So far so good.
When we exit scope, we pop the stack until we reach the token. Every symbol we pass before this we have to take out of our hashmap.
Given following piece of code:
{
a = 5;
{
a = 5;
}
}
Will the hashmap accept this? As in, I would enter them using a as a key. That won’t be a problem, but when popping and having to remove these, will Java be able to make a difference between the two objects? Or will the second one just overwrite the first?
Map javadoc