public static String toString(long[] a) { //Arrays工具类toString()方法的源码
if (a == null) //空指针判断
return "null";
int iMax = a.length - 1;
if (iMax == -1) //空数组判断
return "[]";
StringBuilder b = new StringBuilder();
b.append('[');
for (int i = 0; ; i++) { //省略长度判断,提高效率
b.append(a[i]);
if (i == iMax)
return b.append(']').toString();
b.append(", ");
}
}
2. 多态中的判断,判断是否为继承关系
2.1 使用getClass()方法,重写equals()方法
public boolean equals(Object o) {
// a quick test to see if the objects are identical
if (this == o) return true;
// must return false if the explicit parameter is null or the classes don`t match
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return id == user.id &&
username.equals(user.username) &&
password.equals(user.password);
}