Because StringBuffer
is mutable, and its primary use is for constructing strings. If you want to compare content, call StringBuffer#toString()
and compare the returned value.
It is not generally useful to override hashCode()
for mutable objects, since modifying such an object that is used as a key in a HashMap
could cause the stored value to be "lost."
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…