Customize 'at' with extra parameters for the closure?

让人想犯罪 __ 提交于 2019-12-06 13:46:54

In Groovy you can set default values for optional closure parameters, like so:

static at = { year=null, geo=null ->
    ...
}

I think that'll clear ya up. :)

update

Ok, I know you don't need it anymore, but I made this for my own use when I was learning Groovy, and I thought someone might find it helpful:

  • { -> ... } a closure with exactly zero parameters. Groovy will blow up if you call it with params.
  • { ... } a closure with one optional parameter, named "it"
  • { foo -> ... } a closure with one parameter named "foo" (foo can be any type)
  • { foo, bar, baz -> ... } a closure with 3 parameters named "foo", "bar" and "baz"
  • { String foo -> ... } You can specify the type of the parameters if you like
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!