lundi 22 juin 2015

Execute nested method calls from Method object

I need to make a call to following method -

testObj.getA().getB().getC().getD();

Above, testObj.getA() returns object A which has a method getB(), which returns object B that has method getC(), which returns object C and it has method getD().

How can I invoke it using reflection? If I try Method object as following -

Method m = testObj.getClass().getMethod("getA().getB().getC().getD(), null));

Above fails saying the method is not found. Any suggestions?





Aucun commentaire:

Enregistrer un commentaire