Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.5.4
-
Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
-
Component/s: ast builder
-
Labels:None
-
Environment:Windows 2000, JDK 1.6, Groovy 1.5.4
-
Number of attachments :
Description
Running this in groovyconsole
public class Configuration extends java.util.Properties { } 1
yields the following error:
Exception thrown: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script9: -1: the return type is incompatible with java.lang.String getProperty(java.lang.String) in java.util.Properties. Node: org.codehaus.groovy.ast.MethodNode. At [-1:-1] @ line -1, column -1.
But when the getProperty() method is overridden the code runs fine:
public class Configuration extends java.util.Properties { String getProperty(String s) { } } 1
Adding some details to describe the following conditions in which this problem occurs :-
1) Base class and interface are implemented in java. The base class does not implement this interface. The base class and interface define a method that have incompatible return types but otherwise matching signatures.
2) There is a class in groovy that extends that above mentioned base class and implements the interface. Compiling the groovy class throws the compilation error mentioned in this JIRA item. (groovy does not consider method implementation in Base class as implementation of interface method because of incompatible return type and hence marks considers the interface method as unimplemented and groovy class as abstract)
The code that demonstrates the above conditions is:
Interface and Base class in java:
Subclass in groovy:
"public class Configuration extends java.util.Properties" fails because java.util.Properties has "public String getProperty(String)" and GroovyObject has "public Object getProperty(String)" - same conditions as mentioned above.
Hope it helps.
Roshan