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

null initial value can't be inferred with generic field of a class

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.0-beta-1
    • 2.1.0-rc-1, 2.0.7
    • Static Type Checker
    • None

    Description

      In following code, I expect no STC error at (A).

      import groovy.transform.*
      @TypeChecked // or @CompileStatic
      class ccc {
        List<String> list = null // (A)
        List list2 = null // OK
        String str = null // OK
        public static void main(String [] args) {
          List<String> list = null // OK
        }
      }
      

      but compiler says:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /Users/uehaj/work/201301/gastha_magazine/ccc.groovy: 4: [Static type checking] - Incompatible generic argument types. Cannot assign java.lang.Object to: java.util.List <String>
      @ line 4, column 23.
      List<String> list = null
      ^

      1 error

      Of course I can avoid this error by modify the code to:

           List<String> list = (List<String>)null
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            uehaj UEHARA Junji
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: