嗨,我有以下Groovy代码:这个groovy代码有什么不对?
package fp;
abstract class Function
{
public static Closure map = { action, list -> return list.collect(action) }
}
此代码Groovy IBM developer works系列的拍摄。此代码的文件名是Function
,与类名相同(即使在Groovy中不需要)。当我尝试运行此代码:
groovy Function.groovy
当我运行出现以下错误:
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.
任何一个可以帮助我解决这个问题?
不是说它有所作为,但IBM devel示例类是Functor,而不是Function。你希望能够直接调用抽象类吗?只需明确地遵循IBM devel示例,即可获得您可以从中学习的合理输出。祝你好运! – virtualeyes 2011-06-08 09:21:56