JCK feedback on "Strings in Switch" proposal

Ulf Zibis Ulf.Zibis at gmx.de
Sun May 24 08:37:38 PDT 2009

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:
(2) Comparison for identity would better match to legacy semantics of 
"switch..case" statement.
(3) Don't obstruct later, more general extensions on "switch..case" 
statement. See:

There are 40 votes on Bug ID: 5012262
Please note, that these votes are for "Strings AND Objects in switch",
and not for just "Strings in switch".

Strings, which are only equal, could simply be made identical by 

   switch (myStringFromElsewere.intern()) {
       case STRING1 : ...; // all constants are interned by definition
       case STRING2 : ...; //       "            "
       case "foo" : ...; // automatically interned
       case "bar" : ...; //       "            "


More information about the coin-dev mailing list