这是个好主意吗?如果没有,现在如何解决?
我认为添加一个会很有趣
final boolean identical(Obj obj){
return (this==obj);
}
所以我们有一个改进的等于(逻辑等于)
boolean equals (Obj obj){
return identical(obj); // by default, but its overrideable
}
这个问题源于另一个问题(A Mechanism for have different equals (physical equals andlogical equals) on objects in Collection)需要有一种方法来将相同指针列表与相同对象列表进行比较。有了这个想法,我们可以添加到 Collection 接口:
coll.equals(coll2)
coll.identical(coll2)
coll.identicalElem(coll2){
//current equals implementation of collections but calling identical to compare objects
}
你怎么看?