Hi i have the following Groovy code:
package fp;
abstract class Function
{
public static Closure map = { action, list -> return list.collect(action) }
}
This code was taken from Groovy IBM developer works series. The file name of this code is Function same as class name(even though it is not necessary in case of Groovy). When i try to run this code as:
groovy Function.groovy
When i run i get the following error:
Caught: groovy.lang.GroovyRuntimeException: This script or class could not be run.
It should either:
- have a main method,
- be a JUnit test, TestNG test or extend GroovyTestCase,
- or implement the Runnable interface.
Can any one help me with this issue?
Seems clear enough to me.
To run a Groovy script, the interpreter has to find into it some directly executable code.
It is obviously not the case of your script, that indeed loads perfectly, but can’t be executed as there is no statement in it, only the declaration of an abstract class.