java.util.Objects, round two (original) (raw)
Joseph D. Darcy Joe.Darcy at Sun.COM
Wed Oct 14 17:14:18 UTC 2009
- Previous message: java.util.Objects, round two
- Next message: Sponsoring getting 5015163 "(str) String merge/join that is the inverse of String.split()" into JDK 7
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Paul Benedict wrote:
Joe,
I am confused over this warning:
* Warning: When a single object reference is supplied, the returned * value does not equal the hash code of that object reference. This * value can be computed by calling {@link #hashCode(Object)}.
I first looked into Arrays#deepHashCode and did not see any companion warning there; therefore I am presuming this is new functionality.
No, the behavior is the same. Objects.hash is just a var-arg wrapper around Arrays.hashCode(Object[]). The semantic difference is that for Object.hash, one is passing a number of objects, which happen to get bundled into an array, whereas in Arrays.hashCode an array is being explicitly passed.
Two questions remain based on looking at the javadoc alone and not knowing its implementation:
For when a single object reference is supplied: 1) Why is the hash code not the hash code of the single object? Is there harm in doing so?
As implied by the chain of javadocs, for a single object, hashcode + 31 is returned via the List.hashCode algorithm on a single element list.
-Joe
- Previous message: java.util.Objects, round two
- Next message: Sponsoring getting 5015163 "(str) String merge/join that is the inverse of String.split()" into JDK 7
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]