Strings in Switch

Joseph D. Darcy Joe.Darcy at Sun.COM
Mon Dec 7 16:38:05 PST 2009


Paul Benedict wrote:
> I see that syntactic sugar assumes that the compiler and the runtime
> environment both use the same string hashing algorithm. As noted, the
> algorithm has never changed since at least JDK 1.2. Even if unlikely,
> I don't feel comfortable with this assumption - I do not have an
> alternative to propose either -- but I thought it was worth voicing.
>   

This assumption is explicitly called out in comment in the 
implementation; we are aware of the potential problem and are making a 
different judgment on the comfortability of the implementation strategy.

> Regardless, I see this as a pure detail of one possible
> implementation. Another implementation may not choose to use hash
> codes at all. Am I correct, or am I wrong and the JLS change will
> mandate the use of hashCode for switching?
>   

The JLS will be completely silent on the implementation technique.  The 
entire strings in switch spec change is adding "String, " to the list of 
valid types of expressions that can be switched on.

-Joe




More information about the coin-dev mailing list