Blogger

Delete comment from: Javarevisited

Nitin Taur said...

I do not very much agree with point (4) related to hashcode. Can we use an object as key in hashmap whose hashcode can change once stored in hashmap? Basically this will have same issue as with following class used as key in hashmap:

class A
{
private volatile int i = 1;
@Override
public int hashCode()
{
return ++i;
}
}

I think hashcode should never depend on changing state of object.

Oct 11, 2013, 7:03:53 AM


Posted to Why String is Immutable or Final in Java? Explained

Google apps
Main menu