15 Apr 2004 15:31
Re: One remark and groovyc and a question about closures
On 15 Apr 2004, at 14:17, Fabien Dagnat wrote: > Hello, > I have just discovered groovy, and I must admit it deserve its name... Thanks :) > Just one remark about groovyc: > It seems to use the name of the script as the class name and it can > lead to name clash, for example the script test.groovy containing > only: test = [] leads to: Yes - this is a known issue. Chris & I were chatting on IRC this morning about this, should be a fairly easy fix we think. > >groovyc test.groovy > >>> caught a bug: > >>> uncaught exception during class generation phase on [test.groovy]: > org.codehaus.groovy.syntax.parser.RuntimeParserException: Cannot use a > class expression on the left hand side of an assignment. At [1:1] > test.groovy > >>> stacktrace: .... > I have not looked into groovy source code, but could there be a way to > avoid this clash (for example, by automatically renaming variable > clashing with the name of the script. The trick is to try name your scripts after a class name & be a little careful - though we'll fix it properly soon. > A question: > I would to create (in Java) my own lib to use it in my scripts. I > would like to have a Java class that contain a method taking a groovy > closure as argument. To test this class, I would like to create in > Java a closure object. I cannot find any example of how to this, the > constructor takes a delegate object as argument and I don't how to > create such an object. If you search the code there are a few Closure's used as part of the runtime and for testing. Just derive from Closure and implement a few methods. An example closure is org.codehaus.groovy.runtime.IteratorClosureAdapter James ------- http://radio.weblogs.com/0112098/
RSS Feed