Strings in switch
Ulf.Zibis at gmx.de
Mon Mar 30 12:46:32 PDT 2009
Am 30.03.2009 21:01, Joseph D. Darcy schrieb:
> Ulf Zibis wrote:
>> Hi Joe,
>> I refer to your proposal:
>> If your proposal would unchanged be taken into JDK 7, there won't be
>> any compatible way to implement my more general proposal "Extend
>> switch .. case statement for Object types and simple expressions" in
>> future version of JDK !!!
>> --> So switch .. case statement should compare for IDENTITY if not
>> syntactically determined otherwise.
>> --> compare for EQUALITY would also break semantic of existing switch
>> .. case statement.
> While pattern matching is a fine feature in some languages, I don't
> think retrofitting that flavor of facility onto Java much over and
> above the existing capabilities of the switch statement is the right
> direction to evolve Java.
Joe, thanks for your fast answer.
Another reason, why I'm against comparing for equality by default
syntax, is, that it is good practice to use String constants instead of
widely spreaded String literals with same signature for numerous reasons
(performance, error prone, ...). Your syntax would lead programmers to
stay on widely spreaded String literals.
If constant is not available for switch variable (e.g. if read from
stream), variable could be internalized before, so it's instance becomes
identical to the existing constant.
===>> If just "Strings in switch" is taken over for JDK 7, there is NO
NEED, to compare for equality.
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".
More information about the coin-dev