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

Pattern Matching for switch (Second Preview)

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 18
    • tools
    • None
    • source
    • minimal
    • Java API, Language construct
    • SE

      Summary

      The pattern matching for switch feature should continue to be a preview feature for JDK 18, having been adjusted based on the feedback from being a preview feature in JDK 17.

      Problem

      More time is needed to gain experience with the pattern matching for switch feature. Following feedback from the first preview some small amendments have been make, and feedback on these amendments and the feature in general should be gathered.

      Solution

      The pattern matching for switch preview feature will continue to be a preview feature for JDK 18. The spec and compiler will be adjusted based on the current feedback.

      Specification

      The updated JLS for pattern matching for switch is attached, and is also available for convenience here: http://cr.openjdk.java.net/~gbierman/jep420/jep420-20211111/specs/patterns-switch-jls.html

      The current significant changes to the spec from the first preview are:

      • the any pattern (including an any pattern that is guarded) dominates a constant pattern of the same type
      • permitted types that can't be cast to the selector type of the switch statement or expression (and hence a case cannot be written for them) are ignored when checking exhaustiveness of a switch
      • the specification of the resolution of a switch block has been re-written to be more readable. This is not a semantics altering change, but rather a significant editorial change

      Currently no API changes.

      The changes to the specification and API are a subject of change until the CSR is finalized.

        1. 20211111.diff
          10 kB
        2. jep420-20211020.zip
          35 kB
        3. jep420-20211111.zip
          30 kB

            jlahoda Jan Lahoda
            gbierman Gavin Bierman
            Gavin Bierman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: