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

Cannot compile Map<K,V> == null

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.0, 2.3.1
    • 2.4.0-beta-4
    • Static Type Checker
    • None

    Description

      I cannot compile this code with 2.3.0.

      import groovy.transform.TypeChecked
      
      @TypeChecked
      class TypeTest {
          static interface Map2<K,V> extends Map<K,V> {}
      
          static void main(String[] args) {
              Map2 map = null
              if (map == null) println "map is null"
          }
      }
      

      The error message is

      Error:(9, 13) Groovyc: [Static type checking] - Reference to method is ambiguous. Cannot choose between boolean java.util.Map#equals(java.util.Map), boolean java.util.Map <K extends java.lang.Object, V extends java.lang.Object>#equals(java.lang.Object)

      I can compile if I change it to this.

      if (map == (Object) null)

      Also I can compile this too.

      Map map = null
      if (map == null) println "map is null"
      

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            yukoba Yu Kobayashi
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: