我从 java 类调用覆盖方法时遇到问题。我有以下Java类:
public class Base
{
int state = 0;
public void called()
{
System.out.println("Hello, from called method: " + state);
}
public String getFirst()
{
return "From Base;
}
//
...
//
}
我使用一个 groovy 脚本来覆盖getFirst()
它,以便它调用called()
def base = [ getFirst : {
called() // this line has an error
"From Second"
}] as Base
base.getFirst()
我该如何实现这个?