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

[Base] Shortcut method for "otherwise(when())" combinations

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u20
    • javafx
    • JDK 8u20, Win 7 Pro SP1, 64 Bit

      The "When" class is rather useful to implement "if-then-else" bindings. We noticed that from time to time we write code to the following pattern...

      When(x = v1).then(a).otherwise(when(x = v2).then(b).otherwise(c))

      ...which simply spoken is a "switch" binding.

      Particularly for larger "switch" bindings it would be nice if this could be shortened to...

      When(x = v1).then(a).otherwiseWhen(x = v2).then(b).otherwise(c)

      ...to reduce the level of parenthesis; or even simplified to...

      Switch(x).case(v1, a).case(v2, b).default(c)

      ...which would be really unambiguous to read! :-)

            nlisker Nir Lisker
            mkarg Markus Karg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported: