Here is my code :
result = method1().method2().method3();
I would like to know the execution hierarchy of the above code/statement
Just go through the following points.
- Determine what the leftmost method call will return (let’s call it x).
- Use x as the object invoking the second (from the left) method. If there
are only two chained methods, the result of the second method call is
the expression's result.
- If there is a third method, the result of the second method call is used
to invoke the third method.
As per your statement, the execution hierarchy will be as follows:
- First , method1() which is the leftmost method will be called.
- Suppose method1() returns an object "meth" then the second method (from the left) method2() will be called as meth.method2().
- Last, the object returned from method2() will be used to call the method3().
Hope it clarifies you doubt.