Skip to content
Advertisement

Invoke nested deepobject method via reflection

Is it possible to invoke nested method inside nested object from real object using reflection? Something like this

JavaScript

Real object i have is chatClient and i want to invoke method of class3, which i cannot obtain directly but via class1 path.

Advertisement

Answer

You can have a logic of fetching nested fields in a function inside a for loop , so that you can avoid code duplication.

Whole code example in java:

JavaScript

Here fieldPath in getFieldValue means path of the nested field object.

Advertisement