File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes why equals() not  overridden in StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
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: 24183
    
  34

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://aspose.com/file-tools
 
subject: why equals() not overridden in StringBuffer
 
Similar Threads
I defined an equals method, but Hashtable ignores it. Why?
String manipulation
hascode and equals
Why StringBuffer not override equals??
hashCode() and equals()