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

Generic type of field is not instantiated

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class A<T> {
        T x;
        A(T x) {
          this.x = x;
        }
      }
      
      public class Main {
        public static void main(String[] args) {
          bar((new A<>("")).x);
        }
        public static void bar(String x) {}
      }
      

      Actual Behaviour

      I get the following compile-time error

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 11: [Static type checking] - Cannot find matching method Main#bar(T). Please check if the declared type is correct and if the method exists.
       @ line 11, column 5.
             bar((new A<>("")).x);
             ^1 error
      
      

      Expected Behaviour

      Compile successfully

       

      Tested on: https://github.com/apache/groovy/commit/715c34edc82261544b8715bc2253b0b3f05bdbad

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h