roaster icon indicating copy to clipboard operation
roaster copied to clipboard

Switch using "->" handled incorrectly as switch expression

Open pcimcioch opened this issue 2 years ago • 0 comments

I can write the following method in Java:

enum Direction {LEFT, RIGHT}

void displayDirection(Direction direction) {
  switch(direction) {
    case LEFT -> System.out.println("Turn Left");
    case RIGHT -> System.out.println("Turn Right");
  }
}

This is the correct java code. When I create method with this body though, it gets replaced with something like:

void displayDirection(Direction direction) {
  switch(direction) {
    case LEFT: 
      System.out.println("Turn Left");
      yield;
    case RIGHT:
      System.out.println("Turn Right");
      yield;
  };
}

It seems as if I use "->" in standard switch, library automatically treats it as switch expression

pcimcioch avatar Dec 29 '22 20:12 pcimcioch