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

Type checker does not infer generic type

    XMLWordPrintableJSON

Details

    Description

      The type checker is unable to infer the type of variable value in the below code:

      abstract class Parent<T> {
      	public T value
      }
      
      class Impl extends Parent<Integer> {
      
      }
      
      @CompileStatic
      class Test {
      	public void test() {
      		Impl impl = new Impl()
      		Integer i = impl.value // fails
      	}
      }
      

      The compiler gives this error:

      [Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.lang.Integer

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            djh Henri Pihkala
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: