Click to See Complete Forum and Search --> : java hash output error
Does anyone know why the following gives me an incorrect output.
File file=new File(fileName);
.......
.......
if(file.exists())
System.out.println(file.hashCode());
.......
.......
Thanks,
emus
GaryJones32
05-27-2003, 03:40 PM
What is the output ??
Thanks for the reply,
The output was a negative double int.
As far as I can tell, the hashCode() function can't
be used in this manner.
bwkaz
05-27-2003, 09:56 PM
The Java hashCode() method returns an internal hashing of the object you call it on (hashCode() is defined on the Object class, so every object has that method).
It's meant to aid comparisons -- individual classes can override the default behavior, as long as (this is what I remember from the API spec, anyway) if .equals() would return that two objects are different, their hashCode()s can't be the same. The default implementation returns the address inside the Java virtual machine that the object is stored at.
What do you think it does? It doesn't hash a file's contents...