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

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

Agile BoardAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0-beta-1
    • Fix Version/s: 2.1.0-rc-1, 2.0.7
    • Component/s: Static Type Checker
    • Labels:
      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

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              uehaj UEHARA Junji

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment