dbrin
dbrin

Reputation: 15673

Groovy hasProperty shortcut

I am iterating over a list of objects of mixed types. For each object I access a bunch of properties. Some of these objects will not have some of the properties. Is there a way to avoid using object.hasProperty method to safely access nonexisting properties?

Upvotes: 0

Views: 969

Answers (2)

dbrin
dbrin

Reputation: 15673

looks like the only reasonable way is to use hasProperty method for sanity check

Upvotes: 0

srjit
srjit

Reputation: 526

You could iterate through the object's properties.

The following link might help for this :-

Groovy property iteration

Upvotes: 1

Related Questions