This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes why equals() not  overridden in StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "why equals() not  overridden in StringBuffer" Watch "why equals() not  overridden in StringBuffer" New topic
Author

why equals() not overridden in StringBuffer

Singhal Anuj
Greenhorn

Joined: Mar 28, 2005
Posts: 8
Why java.lang.String overrides equals() method, but java.lang.StringBuffer does not?
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
String is considered one of the 'Value' classes (not sure if that's my term or if I picked it up somewhere). This includes all the primitive wrapper classes and String. They share some characteristics.

They are all immutible. They all override equals, hashCode, and toString. I think they also have some other common methods.

To my knowledge no other class in the standard API overrides equals. I could be wrong here, but I think that's right.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24081
    
  15

No, there are plenty of mutable classes that override equals(); all the java.util Collections classes do, for example.

My guess: they forgot, and then left it that way so as not to break existing code. I think having SB override equals() would be perfectly OK.


[Jess in Action][AskingGoodQuestions]
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I stand corrected, thanks.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: why equals() not overridden in StringBuffer
 
Similar Threads
hascode and equals
Why StringBuffer not override equals??
String manipulation
I defined an equals method, but Hashtable ignores it. Why?
hashCode() and equals()