• Post Reply Bookmark Topic Watch Topic
  • New Topic

equals() in StringBuffer  RSS feed

 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Have a look at this code snippet,



What should ideally happen?
I didnt find any equals() implementation in the StringBuffer class.
I am using JDK 1.4.2.
 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, but I should have serached the forum for similar topics first.
Found what I was looking for here,
Answer

Was curious to know if there is any specific reason for not overriding equals() in StringBuffer.

Thanks and sorry for the inconvinience,
Chinmay.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would imagine it was just an oversight. Remember the curious fact that the oldest classes in the Java APIs were written by people who had no experience at all writing in Java!
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
I would imagine it was just an oversight. Remember the curious fact that the oldest classes in the Java APIs were written by people who had no experience at all writing in Java!


And apparently also not in other OO languages... :roll:
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but StringBuilder (added in 1.5) also does not override equals()...

any other reasons (appart from "just forgotten") ?

cheers

pascal
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by pascal betz:
but StringBuilder (added in 1.5) also does not override equals()...


They probably wanted it to be as compatible to StringBuffer as possible...
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5082260 explains it all.
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
who needs Map anyway :-)

thanks for the link.

pascal
 
bala rajesh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chinmay Bajikar:
Hi,
Have a look at this code snippet,



What should ideally happen?
I didnt find any equals() implementation in the StringBuffer class.
I am using JDK 1.4.2.



Answer
------


== symbols used to compare the content(string)in a object.
but .equals()method is used to compare the string or stringbuffer object;
so sbuf,dbuf or different object, so that the result is sbuf!=dbuf
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by bala rajesh:
== symbols used to compare the content(string)in a object.
but .equals()method is used to compare the string or stringbuffer object;
so sbuf,dbuf or different object, so that the result is sbuf!=dbuf


Huh? For StringBuffer objects, == and equals() do exactly the same thing, because StringBuffer doesn't override equals() (in contrast to String). The original poster asked about the reasoning for this, and I think the previous responses were right on mark. Therefore your responses confuses me quite a bit...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!