Pawel,
I am now beginning to understand more fully the ramifications of equals() and hashCode(). However, clearly Object.hashCode() does not meet your criteria for subclasses--it would cause your equals() method to fail for objects that meet the criteria of being equals(). For example,
Results in the following output:
Clearly the first condition, that for every hashCode() on the
same object, hashCode() returns the same result during a single run of the application BUT for two objects that are equals(), in this case t[0] and t[2], Object.hashCode() does not return the same hashCode() so this violates the general contract of the hashCode() API.
Obviously, this is because hashCode() has not been overridden to provide appropriate hashcodes for
Test objects. I have, using the greatest of all teachers, javac, discovered that you can override a method in base class that was declared native (that was one basic question I had). Now, my basic question is:
How do you compute a hashcode? On what should the hashcode be computed? Thank you all for your assistance; I should have been more precise in my questions.
Steve
sgwbutcher@aol.com [PS I'm sorry Thandapani but I really don't know what you're getting at, I have read and understood the API, it has not helped. I just don't know how to
implement a proper hashCode() method based on the general contract or any contract for that matter.
That is the help I am looking for.
]