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

Using Java Generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.5.6, 1.6-beta-1
    • None
    • None

    Description

      The code

      class BaseA implements Comparable {
          
          int index
          
          public BaseA(){
              index = Math.random() * 10
              println index
          }
      
          public int compareTo(Object a){
              return new Integer(index).compareTo(a.index)
          }
      
      }
      
      
      def a = new BaseA()
      def b = new BaseA()
      
      println( a.compareTo(b) )
      

      Works just fine but if i use the generics version like:

      class BaseA implements Comparable<BaseA> {
          
          int index
          
          public BaseA(){
              index = Math.random() * 10
              println index
          }
      
          public int compareTo(BaseA a){
              return new Integer(index).compareTo(a.index)
          }
      
      }
      
      
      def a = new BaseA()
      def b = new BaseA()
      
      println( a.compareTo(b) )
      

      Gives the error :

      Exception thrown: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script85: 4: Can't have an abstract method in a non-abstract class. The class 'BaseA' must be declared abstract or the method 'int compareTo(java.lang.Object)' must be implemented.
      

      Groovy is not replacing the generic type BaseA in the compareTo parameter.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            ccadete ccadete
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: