Hi

According to the spec the .hashCode() has to return the same value if they
are
equal. Because the equals() method does not return equal for byte[] then it
is
ok to behave so (BTW check if the .hashCode() is the same if you use the
same
reference, I think it should).

Just a simple and stupid way (I assume that the byte array should be the
same
if the content with respect to the order is the same):

Sting lsCode
for( int i = 0; i < bytes.length(); i++ ) {
  lsCode += "" + bytes[ i ];
}
int hashCode = lsCode.hashCode();

OR another way:

int liHashCode = 0;
for( int i = 0; i < bytes.length(); i++ ) {
  liHashCode += bytes[ i ];
}

Have fun

Mad Andy

Because I am not sure about the operator above it is just going through the
bytes
in your array and exclusive or the hashcode from the byte (I think they
return
----- Original Message -----
From: marc fleury <[EMAIL PROTECTED]>
To: jBoss Developer <[EMAIL PROTECTED]>
Sent: Thursday, August 10, 2000 5:12 PM
Subject: RE: [jBoss-Dev] [newbie] byte[].hashcode()


> well I have the wrapper (it is for XidImpl) but I still need the best way
to
> actually *Compute* a byte[] hashCode()
>
> for (int i =....) {
>
>  hashCode = hashCode^(new Byte(byte[i]).hashCode());

I don't think it will work because the Byte[].hashCode() can be different
for
each Byte instance. Therefore I think hashCode will contain a different
value
even when the content is the same.

> }
>
> ????????????? (I don't think that would work actually
>
>
> help me out man
>
> marc
>
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]]On Behalf Of Schaefer, Andreas
> > Sent: Thursday, August 10, 2000 5:00 PM
> > To: 'jBoss Developer'
> > Subject: RE: [jBoss-Dev] [newbie] byte[].hashcode()
> >
> >
> > Hi
> >
> > As far as I know the byte[] super class is Object and it seems that
> > they do not overwrite the standard equals() method (as they also do
> > for the toString()).
> > I also checked Byte[] because its superclass is Object[] but it is
> > the same.
> >
> > I think their is no way to go around except to write a wrapper class
> > around byte[], eh?
> >
> > Have fun
> >
> > Mad Andy
> >
> > > -----Original Message-----
> > > From: marc fleury [mailto:[EMAIL PROTECTED]]
> > > Sent: Thursday, August 10, 2000 4:50 PM
> > > To: jBoss Developer
> > > Subject: [jBoss-Dev] [newbie] byte[].hashcode()
> > >
> > >
> > > did you know that
> > >
> > > byte[] byte1 = {1,2,3};
> > > byte[] byte2 = {1,2,3};
> > >
> > > yields
> > > byte1.equals(byte2) = false;
> > > and
> > > byte1.hashCode() != byte2.hashCode();
> > >
> > > blows my mind man....
> > >
> > > what is the best way to compute a byte[].hashCode()?
> > >
> > > regards
> > >
> > > marc
> > >
> > > sorry for the newbie question :))))
> > >
> > > ________________________
> > > Marc Fleury
> > > Chief Technology Officer
> > > Telkel, Inc.
> > > ________________________
> > >
> >
> >
>
>


Reply via email to