Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9253

Comparison between Enum and other objects should fail

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      In Java, comparison between Enum and other objects always triggers an error when compiling.

      Groovy can follow the same behavior (at least in @CompileStatic mode) to keep consistency.

       

      package com.company.test
      
      import groovy.transform.CompileStatic
      
      @CompileStatic
      class TestEnumGroovy {
          enum E {
              a,b
          }
          static void main(String[] args) {
              E x = E.a
              String s = "A"
      
              System.out.print(x == s)  // it causes an error in Java. But Groovy doesn't see the error.
          }
      }
      
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            wxiaoguang Xiaoguang Wang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: