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

Switch with unnamed patterns erroneously non-exhaustive

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 22
    • 21
    • tools
    • 21
    • b03

    Backports

      Description

        sealed interface Animal permits Dog, Chicken {};
        record Dog(String name, int age) implements Animal {};
        record Chicken(String name, int age) implements Animal {};

        void main() {
            Animal a1 = new Dog("Yodel", 4);
            Animal a2 = new Chicken("Purple Head", 5);

            switch (a1) {
                case Dog(var name, _) -> System.out.println("Dog: " + name);
                case Chicken(var name, _) -> System.out.println("Chicken: " + name);
                // default -> System.out.println("Unknown animal");
            }
        }

        Attachments

          Issue Links

            Activity

              People

                abimpoudis Angelos Bimpoudis
                abimpoudis Angelos Bimpoudis
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: