我有一个groovy类,能够将其输出写入StringWriter – (通过setStringWriter方法).
filter.setStringWriter(new StringWriter(){ @Override public void write(String string){ // do something with the string } });
对于Groovy我被告知要使用一个闭包,我尝试了以下但没有运气:
def s = {String line -> print line} as StringWriter filter.setStringWriter(s)
要么
filter.setStringWriter{String line -> print line}
我该怎么做呢,或者甚至可能吗?