check identities in String.equals(), etc.

This commit is contained in:
Joel Dice 2007-08-01 17:46:05 -06:00
parent b56eed68be
commit 6ddb8c839c

View File

@ -65,14 +65,16 @@ public final class String implements Comparable<String> {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
return o instanceof String && compareTo((String) o) == 0; return this == o || (o instanceof String && compareTo((String) o) == 0);
} }
public boolean equalsIgnoreCase(String s) { public boolean equalsIgnoreCase(String s) {
return compareToIgnoreCase(s) == 0; return this == s || compareToIgnoreCase(s) == 0;
} }
public int compareTo(String s) { public int compareTo(String s) {
if (this == s) return 0;
int d = length - s.length; int d = length - s.length;
if (d != 0) { if (d != 0) {
return d; return d;
@ -88,6 +90,8 @@ public final class String implements Comparable<String> {
} }
public int compareToIgnoreCase(String s) { public int compareToIgnoreCase(String s) {
if (this == s) return 0;
int d = length - s.length; int d = length - s.length;
if (d != 0) { if (d != 0) {
return d; return d;