Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implement HashCode() for a node containing only reference to next node?

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.
    }
}

From the comment in the code, my question is actually how to uniquely identify reference itself, like address in C.

like image 243
Helin Wang Avatar asked Jan 28 '26 18:01

Helin Wang


1 Answers

There is nothing you need to do here, the Node already has the default implementation which returns a hash code based on the memory location it resides at.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!