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

Improper "duplicate case label" error

XMLWordPrintable

    • b55
    • Verified

        Consider the following code:
        ---
        enum EnumSwitch {
            A, B;
            public static int c(EnumSwitch e) {
                switch (e) {
                    case EnumSwitch.A: return 1;
                    case EnumSwitch.B: return 2;
                }
            }
        }
        ---

        Compiling this will produce these three errors:
        ---
        EnumSwitch.java:5: error: an enum switch case label must be the unqualified name of an enumeration constant
                    case EnumSwitch.A: return 1;
                                   ^
        EnumSwitch.java:6: error: an enum switch case label must be the unqualified name of an enumeration constant
                    case EnumSwitch.B: return 2;
                                   ^
        EnumSwitch.java:6: error: duplicate case label
                    case EnumSwitch.B: return 2;
                    ^
        3 errors
        ---

        The first two errors are appropriate, but the third one is not: there is no duplication in the labels.

        This has originally been filed as part of JDK-8048805.

              sadayapalam Srikanth Adayapalam (Inactive)
              jlahoda Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: