Originally posted by Kishore Dandu:
In my experience StringBuffer is the one which does not override equals and hashcode methods.
Well there's a method to this madness. Since StringBuffer
objects are mutable, how would you propose to improve on
the implementation of hashCode() inherited from Object?
StringBuffer sb = new StringBuffer("bar");
Hashtable ht = new Hashtable();
ht.put(sb, Boolean.TRUE);
sb.reverse(); // now contains "rab"
boolean found = ht.containsKey(sb);
Is it ok with you if found==false here?