Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

contentEquals in java.lang.String

 
Vijay Raj
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

The String class in Java 5 has two contentEquals(), one that takes in a StringBuffer and another that takes in a CharSequence. contentEquals(CharSequence) was introduced in Java 5 AND StringBuffer IS-A CharSequence as in implements it.

Now, the question. Why do we need contentEquals(StringBuffer) in Java 5. Won't contentEquals(CharSequence) be enough.

One solution to this would be that programs written in Java 1.4 won't run in a Java 5 runtime if contentEquals(StringBuffer) is removed. But then, won't contentEquals(CharSequence) take its place.

regards,
vijay.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The CharSequence version would take its place if you recompiled your code. But removing the method would break binary compatibility -- i.e., code that wasn't recompiled wouldn't work if it called the StringBuffer method.

To the best of my knowledge Sun has actually never removed a method from the API.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic