JDK-7123479 : Changing of SWITCH statement
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 6u29
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2011-12-21
  • Updated: 2012-07-24
  • Resolved: 2012-07-24
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
There is a disavantage of SWITCH statement  (in comparsion with C): it can't receive range of values or conditions as case parameters.


JUSTIFICATION :
It is necessary because it will significiantly reduce the code writing for switch statement and make it much more flexible and east-to-use

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should work at any expr variable randomed value.

ACTUAL -
But now switch statement doesn't work if cases about range (3;7] and  [1;3] exist. I think it will be very useful to add support of contions and ranges of values to Java like it is in C.

---------- BEGIN SOURCE ----------
int expr=(int) (Math.random()*10);
	switch (expr) {
	  case 1...3:
	   //There goes some code
	   break;
	  case 0:
	   //There goes some code
	   break;
	  case >3,<=7:
	//There goes some code
	break;
	 default:
	//There goes some code
	}
---------- END SOURCE ----------

Comments
EVALUATION In Java SE 7, the switch statement was enhanced to support strings. Other elaborations of the switch statement are not planned.
23-07-2012