[jdom-interest] Re: Inconsistancy in Namespace.hashCode().

Joseph Bowbeer jozart at csi.com
Wed Feb 28 17:48:31 PST 2001


>     public int hashCode() {
>         return (prefix+uri).hashCode();
>     }
>

Avoiding the string concatentation every time would be more efficient.
Constructing the hashCode from prefix.hashCode() and uri.hashCode() should
suffice:

  return 31*prefix.hasCode() + uri.hashCode();

In fact, the two formulas should produce identical results in JDK1.3,
provided prefix and uri are non-null.

The hashCodes in String are cached.  Namespace could cache its hashCode,
too, but the computation above is probably fast enough.


----- original message -----

From: Jason Hunter jhunter at collab.net
Date: Wed, 28 Feb 2001 14:45:39 -0800

"Steven D. Keens" wrote:
>
> I have been looking at the code a little and came across
> a discrepency between the function's documentation and its
> behaviour.  Here's the code:
>
>     public int hashCode() {
>         return (prefix+uri).hashCode();
>     }
>

This correctly defines the behavior, and I think the existing behavior is
correct.  Anyone (Elliotte esp) have concerns?






More information about the jdom-interest mailing list