JCK feedback on "Strings in Switch" proposal
Joseph D. Darcy
Joe.Darcy at Sun.COM
Sun May 24 12:21:53 PDT 2009
Ulf Zibis wrote:
> Am 19.05.2009 14:42, Dmitry Miltsov schrieb:
>> Hello,
>>
>> The JCK engineers have reviewed the "Strings in switch" proposal
>> and found one issue to clarify.
>>
>> "14.11 The switch Statement" states:
>> ------------------------------------------------------------------
>> ...
>> Otherwise, execution continues by comparing the value of the
>> Expression with each case constant. Then there is a choice:
>> * If one of the case constants is equal to the value of the
>> expression, then we say that the case matches ...
>> ------------------------------------------------------------------
>>
>> It would be good to clarify what "equal" means in case of the
>> String values. It would be useful to mention that in this case
>> the result of comparison will be "expression.equals(constant)",
>> not "expression == constant" as for other types.
>>
>
> I think it would be better to define "expression == constant" for
> several reasons.
> (1) "switch..case" syntax historically is expected to be very fast.
> See discussions on:
> http://forums.java.net/jive/message.jspa?messageID=4146#4146
> http://forums.java.net/jive/message.jspa?messageID=14216#14216
> http://forums.java.net/jive/thread.jspa?threadID=504
> (2) Comparison for identity would better match to legacy semantics of
> "switch..case" statement.
No, it would not. Comparing strings for "==" equality is a common
programming error so the semantics of strings in switch should be
defined in terms of .equals equality.
-Joe
More information about the coin-dev
mailing list