Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > hashCode for byte[]

Reply
Thread Tools

hashCode for byte[]

 
 
Roedy Green
Guest
Posts: n/a
 
      08-22-2003
What algorithm is used for hashCode for byte[]. Where do you look to
see it? Do you have to invent your own wrapper class to get a decent
one?

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Dale King
Guest
Posts: n/a
 
      08-22-2003
"Roedy Green" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What algorithm is used for hashCode for byte[]. Where do you look to
> see it? Do you have to invent your own wrapper class to get a decent
> one?


From section 10.7 in the JLS:

The members of an array type are all of the following:
- The public final field length, which contains the number of components of
the array (length may be positive or zero)
- The public method clone, which overrides the method of the same name in
class Object and throws no checked exceptions
- All the members inherited from class Object; the only method of Object
that is not inherited is its clone method

That says that the it uses the equals and hashCode methods from Object,
which are actually native methods and thus VM dependent but are usually a
permutation of the address of the object itself.

What Sun really needs to do is to define an interface like Comparable for
use with HashMap and HashSet. This interface would implement the methods:

equals( Object a, Object b )
hashCode( Object a )

This would allow you to establish your own criteria for when objects are
equal.

--
Dale King


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating hashcode in double hashing Mikke Java 7 05-24-2004 09:12 PM
Hashcode of primitive types Dimitri Pissarenko Java 5 01-29-2004 11:05 PM
Improving hashCode() to match equals() Marco Java 10 01-17-2004 09:55 PM
Designing hashCode() methods kelvSYC Java 1 12-24-2003 02:56 AM
equals and hashCode Gregory A. Swarthout Java 2 12-20-2003 12:34 AM



Advertisments