United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6827009 Project Coin: Strings in Switch
JDK-6827009 : Project Coin: Strings in Switch

Details
Type:
Bug
Submit Date:
2009-04-06
Status:
Closed
Updated Date:
2014-03-13
Project Name:
JDK
Resolved Date:
2012-01-13
Component:
tools
OS:
linux,generic,windows_98,windows_xp,windows_2000
Sub-Component:
javac
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0,1.4.2,5.0,6,7
Fixed Versions:

Related Reports
Duplicate:
Relates:
Relates:
Relates:
Relates:
Relates:
Relates:
Relates:
Relates:

Sub Tasks

Description
One of the language changes in Project Coin is allowing strings to be switched on; this bug tracks that work.

                                    

Comments
EVALUATION

A fine idea.
                                     
2009-04-06
EVALUATION

We can/should use this language feature as a prototypical JDK 7 feature in test/tools/javac/versions/check.sh
                                     
2009-05-21
PUBLIC COMMENTS

See
http://hg.openjdk.java.net/jdk7/m5/langtools/rev/8fb9b4be3cb1
                                     
2009-11-03
PUBLIC COMMENTS

For possible future work, specialized translations for
well-behaved two-alternative string switches into
if-based structures could be added.  Well behaved in
this context either means no fallthroughs or
unconditionally always falling through from the first
alternative into the second.

With two alteratives, there are six cases to consider,
three combinations of "case" and "default" with and
without fallthroughs:

1) case "a": Stmts_a
  default:  Stmts_default

2) default:  Stmts_default
  case "a": Stmts_a

3) case "a": Stmts_a
  case "b": Stams_b

When there is not a fallthrough, the switch block can
be translated into an if() ... else structure:

1) if(s.equals("a"))
     Stmts_a minus any trailing break
  else
     Stmts_default minus any trailing break

2) if(!s.equals("a"))
     Stmts_default minus any trailing break
  else
     Stmts_a minus any trailing break

3) if(s.equals("a"))
     Stmts_a minus any trailing break
  else if (s.equals("b"))
     Stmts_b minus any trailing break

A trailing break means the last statement on the list
is an unlabeled break.

With a fallthrough from the alternative, an if inside a
block can be used:

1) {
      if(s.equals("a"))
         { Stmts_a }
      Stmts_default minus any trailing break
  }

2) {
      if(!s.equals("a"))
         { Stmts_default}
     Stmts_a minus any trailing break
  }

3) {
      boolean $fallthrough = false;
      if (s.equals("a") {
          Stmts_a
          $fallthrough = true;
      }
      if (s.equals("b") || $fallthrough)
         {Stmts_b minus any trailing break}
  }
                                     
2009-11-04
EVALUATION

http://hg.openjdk.java.net/jdk7/build/langtools/rev/8fb9b4be3cb1
                                     
2009-11-09



Hardware and Software, Engineered to Work Together