Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
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.