如何为仅包含对下一个节点的引用的节点实现HashCode()?

Hel*_*ang 2 java reference hashcode

public class Node {
    private Node nextNode;

    @Override
    public int hashCode() {
        //How to implement this?
        //Because you just have a attribute which is a reference.
        //I think the attribute is almost useless, because if you use the HashCode of the attribute, you will finally fall into a useless loop.
        //Thus, I think you should find a way to represent the HashCode of reference (instance) itself.
    }
}
Run Code Online (Sandbox Code Playgroud)

从代码中的注释,我的问题实际上是如何唯一地标识引用本身,如C中的地址.

小智 9

你不需要在这里做任何事情,Node已经有了默认的实现,它根据它所在的内存位置返回一个哈希码.