Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7123479

Changing of SWITCH statement

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u29
    • specification
    • x86
    • windows_xp

      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 ----------

            abuckley Alex Buckley
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: