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

Strange error message when switching over long

    XMLWordPrintable

Details

    • b08

    Backports

      Description

        When I use this code:

        long l = 8L;
        int x = switch (l) {
            case 8L -> 1;
            case 4L -> 2;
            default -> throw new UnsupportedOperationException();
        }

        I get this error message (copied from jshell):

        | Error:
        | constant label of type long is not compatible with switch selector type long
        | case 8L -> 1;
        | ^^
        | Error:
        | constant label of type long is not compatible with switch selector type long
        | case 4L -> 2;
        |

        This looks like a bug, as I'd expect 'long' to be compatible with 'long'.

        Attachments

          Issue Links

            Activity

              People

                jlahoda Jan Lahoda
                jvernee Jorn Vernee
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: