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

Cannot pass numeric constant to a method with a generic type

    XMLWordPrintableJSON

Details

    Description

      I have the following Groovy program.

      @groovy.transform.TypeChecked
      class Main {
        public static final void main(String[] args) {
          final A<Float> a = new A<Float>()
          a.foo(10)
          a.bar(10) // Fails here
        }
      }
      
      final class A<T> {
        final void foo(Float x) {}
        final void bar(T x) {}
      }
      
      

      Actual Behavior

      The program does not compile, and I get the following error.

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 6: [Static type checking] - Cannot call A <Float>#bar(java.lang.Float) with arguments [int]
       @ line 6, column 5.
             a.bar(10)
             ^
      
      1 error
      

      Expected Behavior

      Compile successfully.

      Attachments

        Activity

          People

            Unassigned Unassigned
            schaliasos Stefanos Chaliasos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: