mardi 24 octobre 2017

Groovy: Get the children of a class [duplicate]

Is there any way to get all the descendants names of a class?

The hierarchy of my class is something like this:

[ ParentClass ]

[ Battery extends ParentClass ]
[ Cover extends ParentClass ]
[ Dispense extends ParentClass ]
[ Known extends ParentClass ]
[ Product extends ParentClass ]

I'm doing something like that:

['Battery', 'Cover', 'Dispense', 'Known', 'Product'].each {
    def className = "com.package.${it}"
    ...
}

But if in a future we add a child I will need to add another element in the array.

And I shouldn't add this code in the domain, because is something that marshallize stuff.





Aucun commentaire:

Enregistrer un commentaire