hashCode for byte[]

Discussion in 'Java' started by Roedy Green, Aug 22, 2003.

  1. Roedy Green

    Roedy Green Guest

    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.
     
    Roedy Green, Aug 22, 2003
    #1
    1. Advertising

  2. Roedy Green

    Dale King Guest

    "Roedy Green" <> wrote in message
    news:...
    > 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
     
    Dale King, Aug 22, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    1
    Views:
    856
    Jonathan Bromley
    May 4, 2004
  2. Bharat Bhushan

    Appending byte[] to another byte[] array

    Bharat Bhushan, Aug 5, 2003, in forum: Java
    Replies:
    15
    Views:
    40,264
    Roedy Green
    Aug 5, 2003
  3. Jean-Daniel Gamache
    Replies:
    0
    Views:
    428
    Jean-Daniel Gamache
    Jul 14, 2004
  4. Peter
    Replies:
    3
    Views:
    731
    Michael Borgwardt
    Aug 5, 2004
  5. Kirby
    Replies:
    3
    Views:
    653
    Kirby
    Oct 8, 2004
Loading...

Share This Page