Access values of static closure in Groovy -


I would like to store some properties in a static closing and later would like to use them during a method call:

  class person {static someMap = {key1: "value1", key2: "value2"}}  

So how can I write a method within the person , Who stored this data?

For a simple matter, you're better off using a map.

If you really want to evaluate it as closing (possibly to make your own DSL), then you have to change your syntax a bit as John says.

This is a way of using a builder class to evaluate "some" closing to block and block calls with Gravy Metprograming method / property to save them: SomethingBuilder {Map valueMap = [:] SomethingBuilder (object) {def callable = object.Something callable.delegate = this callable.resolveStrategy = Closure.DELEGATE_FIRST colebabel ()} def proportmings (string name ()) { Return valueMap [name]} def PropertyMacing (string name, value) {valueMap [name] = value} def methodMi Ssing (string name, args) {if (args.size () == 1} {valueMap [name] = Args [0]} and {valueMap [name] = args}}} class person {static object = {key1 " Value1 "// Call Message Missing (" Key 1 ", [" Value 1 "] key2 (" value2 ") / / Call Message Ing (" Key2 ", [" Value2 "]) Key3 =" Value 3 "// calls propertymaking key (" key3 "," value3 ") key4" afoo "," bar "," bez "// call message missing (" key4 "" key1 "// call propertymissing (" key 1 " ")" Value1 "== Producer says" Value2 "== Builder." Key2 "// calls propertymanning (" key 2 ")" value 3 Key3 "// calls propertymanning (" 3 ") [" foo "," bar "," buzz ""] == builder. "Key4" // calls property milling ("key 4 ")


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -