15 Apr 2004 18:39
Re: 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."
> }
>
> }
>
> Then in the Java code I have
> GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
> Class clazz = groovyClassLoader.parseClass(new
> File("FolderAction.groovy"));
> Object script = clazz.newInstance();
> FolderActions actions = (FolderActions)script;
> actions.onAdd(new File("Hello"));
>
> But when the "actions.onAdd" method is called I get
> java.lang.AbstractMethodError: FolderAction.onAdd(Ljava/lang/File;)V
Note that this means that there's no method called
void onAdd(File)
James
-------
http://radio.weblogs.com/0112098/
RSS Feed