jastrachan | 15 Apr 19:34 2004
Picon

Re: Embedding Groovy and Java Interfaces

On 15 Apr 2004, at 18:26, Galarneau, Neil wrote:
>> -----Original Message-----
>> From: groovy-user-admin@... On Behalf Of 
>> jastrachan@...
>> Sent: Thursday, April 15, 2004 12:40 PM
>> To: groovy-user@...
>> Subject: Re: [groovy-user] Embedding Groovy and Java Interfaces
>>
>> By default the return type of methods is 'Object' currently in groovy
>> unless you specify it.
>>
>> So I suspect you need to specify 'void' on your groovy script...
>>
>>> I have a Groovy script defined in the file FolderAction.groovy
>>
>>> import java.io.File
>>> import name.erikhusby.folderwatcher.FolderActions
>>>
>>> class FolderAction implements FolderActions {
>>
>> try adding void before these method names...
>>
>>>    onAdd( file ) {
>>>        println "File " + file + " added."
>>>    }
>>>
>>>    onDelete( file ) {
>>>        println "File " + file + " deleted."
>>>    }
>>>
>>>    onModify( file ) {
>>>        println "File " + file + " modified."
>>>    }
>>>
>>> }
>
> So should the Groovy compiler complain that the interface
> is not implemented and the class has to be abstract?

Absolutely! We should do better validation of the groovy code to give 
more meaningful errors to users.

Indeed we could even be clever enough to spot this common gotcha. Plus 
we could warn that overloading a method & changing the return type can 
confuse Java compilers.

> Of course groovyc could check for this case and either do what
> is expected or give a better error message because it sounds
> like this issue won't be rare.

Agreed.

James
-------
http://radio.weblogs.com/0112098/

Gmane