The best you could do is get the hashcode via System.identityHashCode(java.lang.Object), as Object.hascode() is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.
It's worth mentioning that this kind of construct is considered a poor programming practice due to the way String objects and literals work in Java (Strings are immutable and one should avoid creating unnecessary objects). The following is preferred:
Michael Lloyd Lee
Joined: Sep 07, 2005
Originally posted by saxena vicky: Thanks Michael ! But the value return from System.identityHashCode(java.lang.Object), as Object.hascode() are different, why ?
Maybe I should of clarified that as java.lang.Object.hashCode().
They should return different values, as hashCode() is overridden by String (to the method shown above).