The code is groovy but the answer can be in Java, no problem. I have a Person class with the following attributes:
class Persona(){
String nombre
String apellido
}
and I have a method that returns two person type objects, one with some attributes and the other with the rest. In my example it would be as if I had:
persona1 = "nombre : Juan"
persona2 = "apellido : Gónzalez"
And when "merging" it, what I want is that person1 be added the attributes that it does not have but that person2 does have. The output in this example would be:
persona1.merge(persona2)
persona1= "nombre : Juan, apellido : Gónzalez"
Is there a java or groovy api method that allows me to do this "merge" without writing each attribute by hand (iterating over all the attributes so I don't have to change the code if attributes are added or removed)?
If it doesn't exist, can you make a loop to iterate over the different attributes of a class to check the value of that attribute one by one?