JDK-6827009 : Project Coin: Strings in Switch
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.0,1.4.2,5.0,6,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS:
    generic,linux,windows_98,windows_2000,windows_xp generic,linux,windows_98,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2009-04-06
  • Updated: 2021-03-03
  • Resolved: 2012-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b76Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
One of the language changes in Project Coin is allowing strings to be switched on; this bug tracks that work.

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

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} }
04-11-2009

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

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

EVALUATION A fine idea.
06-04-2009