I have a HashMap:
private HashMap cardNumberAndCode_ = new HashMap();
And later I do this:
The get method returns a copy of the reference to the stored integer...
Assigning a new value to the variable storing this copy in order to point to the value 10 will not change the reference in the map.
It would work if you could do balance.setValue(10), but since Integer is an immutable class, this is not an option.
If you want the changes to take affect in the map, you'll have to wrap the balance in a (mutable) class:
class Balance {
int balance;
...
}
Balance balance = cardNumberBalance_.get(cardNumber);
System.out.println(balance.getBalance());
balance.setBalance(10);
Balance newBalance = cardNumberBalance_.get(cardNumber);
System.out.println(newBalance.getBalance());
But you would probably want to do something like this instead:
cardNumberBalance_.put(cardNumber, 10);