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

More problems with covariant return types

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.5.2, 1.6-rc-2
    • 1.5.2, 1.6-rc-2
    • class generator
    • None

    Description

      This is related to the issue that was fixed in GROOVY-2320. Consider the following Java code:

      import java.util.concurrent.*;
      
      public class Test {
          public static void main(String[] args) {
              assert "x" == new CallableTask().call();
          }
      
          abstract static class AbstractCallableTask<T> implements Callable<T> { }
      
          abstract static class SubclassCallableTask<T> extends AbstractCallableTask<T> { }
      
          static class CallableTask extends SubclassCallableTask<String> {
              public String call() { return "x"; }
          }
      }
      

      This code compiles and works as expected, but I can't get the Groovy version to work:

      import java.util.concurrent.*;
      
      assert "x" == new CallableTask().call();
      
      abstract class AbstractCallableTask<T> implements Callable<T> { }
      
      abstract class SubclassCallableTask<T> extends AbstractCallableTask<T> { }
      
      class CallableTask extends SubclassCallableTask<String> {
          public String call() { return "x"; }
      }
      

      I get the following exception:

      $ groovy Test.groovy
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Test.groovy:
      9: Can't have an abstract method in a non-abstract class. The class 'CallableTask' must be
      declared abstract or the method 'java.lang.Object call()' must be implemented.
       @ line 9, column 1.
         class CallableTask extends SubclassCallableTask<String> {
         ^
      
      1 error
      

      I've tested with 1.5.0 and trunk. I have a patch to GenericsTest.groovy attached. I ran into this problem in the course of working with a Groovy subclass of this class: https://svn.mpl.ird.fr/ichthyop/trunk/ichthyop/util/SafeSwingWorker.java

      Attachments

        1. covariant-subclass.diff
          2 kB
          Mike Dillon

        Activity

          People

            blackdrag Jochen Theodorou
            md5 Mike Dillon
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: