logo       

No anonymous inner classes?: msg#00158

lang.groovy.user

Subject: No anonymous inner classes?

I'm trying to embed a groovy script into an application. The application has a Java interface that a class in the groovy script implements. There is another Java interface in the application called Command with method execute(); I want to be able to execute a command written in the groovy script by passing it to the java application, but I get an "Anonymous inner classes not yet supported Exception"

I tried making a normal inner class, but that seems to be not working either; are normal inner classes supported in groovy?

Basically, I have something like this:

Java interfaces:
public interface foo {
foo1();
foo2();
}
public interface Command {
execute();
}

Groovy class:
class bar implements foo {
foo1() {}
foo2() {
javaSingleton.instance().executeCommand(new Command() {
public void execute() {
foo3();
}
}
}
private void foo3() {
//do some cool stuff
}
}

The problem is I can't use the anonymous inner class. Is there a way to make a closure do what I want (ie: implement the Command() interface)? I don't really understand closures yet, so I'm not sure what they can and cannot do. Is there another way around this problem?

I'll ask now; are regular inner classes supported in Groovy? if they are, I can use that. I'm just assuming they aren't because of problems I had, but perhaps I implemented it incorrectly.

thanks,
Dusty



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise