2020-07-23(Object对象常用方法)
2020-07-23 本文已影响0人
残烛_商志飞
1,hashcode()
返回值为地址,例如:
Object obj = new Object();
System.out.println(obj.hashCode());
2,getClass()
Returns the runtime class of thisObject:返回运行时的类;
3,toString()
Returns a string representation of the object.
源码:
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
toString通常重写用来显示对象的信息;
4,equals()
Indicates whether some other object is "equal to" this one
源码:
public boolean equals(Object obj) {
return (this == obj);
}
所以equals只能比较引用数据类型