//一直按着Ctrl,鼠标移到String这个字上,左键单击,出现源代码。
public class Fu {
private final char value[];
//String源代码复制。
public Fu() {
this.value = new char[0];
}
//String源代码复制,Fu改为你自己的类名。
public boolean equals(Object anObject) {
if (this == anObject) {
return true;
}
if (anObject instanceof Fu) {
Fu anotherString = (Fu) anObject;
int n = value.length;
if (n == anotherString.value.length) {
char v1[] = value;
char v2[] = anotherString.value;
int i = 0;
while (n-- != 0) {
if (v1[i] != v2[i])
return false;
i++;
}
return true;
}
}
return false;
}
//String源代码复制,Fu改为你自己类名。
public static void main(String[] args) {
Fu ee=new Fu();
Fu ff=new Fu();
System.out.println(ee.equals(ff));
//不再是Object根类里equals方法比较两对象引用地址,而是自己类里equals方法比较两对象内容。
}
}