Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一个元类如何成为一个接受对象和闭包的方法?
具体来说,
public void eachRow(GString gstring, Closure closure)
我想 metaClass eachRow() 以便它打印 gstring 参数,并忽略闭包。目标是创建一个应用程序,当传递某个参数时,它会使用 groovy.sql.Sql 执行某种“空运行”执行,而不是执行查询,它只是打印它通常会执行的语句。
所以我认为我的问题不是我如何定义方法,而是我是什么(或没有返回)。这似乎工作......
sql.metaClass.eachRow = { String qry, Closure c -> println qry new GroovyRowResult([:]) // I was returning null, adding this fixed me. }