Object
类是一切 Java 类的父类
Quote
Of course, a variable of type Object is only useful as a generic holder for arbitrary values. To do anything specific with the value, you need to have some knowledge about the original type and apply a cast:
原来书里早就教我了,之前 JavaWeb 中,JDBC 用过这样的方法
The equals
Method
最好使用
Object.equals(a, b)
而不是a.equals(b)
,可以避免null
引起的 bug,同时顶在逻辑最早表达,可以截断防止引用null
在设计 equals
方法时,和离散数学的等价类同定义
如何写一个完美的 equals
方法
参见 Core Java, Vol I, p 236.
The hashCode
Method
“哈希值是一个整数产生自一个对象。”