Declare variable with name equal to a value?

0

Many times I have needed to declare a variable and that its name is the value of another variable dynamically.

Something like this: Example:

JSONObject fieldGruop = new JSONObject()  //objeto json
//aqui itero por un array de objectos
Field.findAllByFieldGroupId(binding.groupId).each{ field ->  
//aqui quiciera crearle al objeto "fieldGruop" propiedades con nombre igual al valor "name" de los field.
fieldGruop.${field.name} = cualquierValue  //Mi duda es la Sintaxis
}

Thanks in advance.

    
asked by Luis 18.05.2018 в 19:56
source

0 answers