This content has been marked as final. Show 3 replies
811678 wrote:If you mean you want to use method chaining in your Java code's use of reflection, like invoke().invoke().invoke(), then no, you cannot.
I'm doing some work with reflection and am using the class java.lang.reflect.Method to invoke methods (using the, er, "invoke" method).
One aspect of the work I'm doing involves method chaining, e.g. myObject.aMethod().anotherMethod().yetAnotherMethod();
Looking at the API docs, the invoke() method only seems to accept a single method call and its associated parameters. Can method chaining be modelled using reflection?
Thanks for any thoughts.
If you mean you're parsing some string and using it to reflectively invoke a method named by that string, then sure, just add the appropriate parsing code and apply the results to the underlying reflective code just like you're doing for a single method name and arg list.