Every competent Java programmer knows that you need to use String.equals() to compare a string, rather than == because == checks for reference equality.
When I'm dealing with strings, most of the time I'm checking for value equality rather than reference equality. It seems to me that it would be more intuitive if the language allowed string values to be compared by just using ==.
As a comparison, C#'s == operator checks for value equality for strings. And if you really needed to check for reference equality, you can use String.ReferenceEquals.
Another important point is that Strings are immutable, so there is no harm to be done by allowing this feature.
Is there any particular reason why this isn't implemented in Java?
==
is object equality andeq
is reference equality (ofps.oreilly.com/titles/9780596155957/…). – Giorgio Apr 2 at 11:12==
operator always maps to equals() method (when objects are involved) - probably because that's the more common case; Reference identity requires an explicit function call. – aviv Apr 3 at 2:55