Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Java 17 preview switch with exception throw #683

@wangxufire

Description

@wangxufire

error: expected token: 'case'; generated default instead

example:

  interface Test {}

  static class Test1 implements Test{}
  static class Test2 implements Test{}

  public static void main(String[] args) {
    Test test = new Test1();
    switch (test) {
      case Test1 test1 -> {}
      case Test2 test2 -> {}
      default -> throw new IllegalStateException("Unexpected value: " + test);
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions