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

Clarify the conversions permitted in pattern matching

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 22
    • None
    • specification

      The introduction of pattern matching for the `instanceof` operator (JEP 394) and for `switch` statements and expressions (JEP 441) has created a family of language constructs where compatibility of an expression may require an implicit conversion from the expression to a target type given by a pattern.

      Currently the JLS identifies the constructs and conversions relevant to pattern matching by extending the notion of _casting context_ (5.5) and using a restricted form of casting conversion.

      This is unnecessarily complicated, and given that future pattern matching constructs will require yet more specialized conversions, we should decouple the spec of pattern matching from the spec of casting. To that end, we should introduce a new section 5.7 "Testing Contexts" that identifies the pattern matching constructs and specifies a new "testing conversion" relation.

      This change is purely presentational - no semantic changes to the language are involved - but will serve as a better foundation for development of new language features in this area.

            gbierman Gavin Bierman
            gbierman Gavin Bierman
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: