ThisChildInCallExpressionDRAFT
In an expression tree of an expression involving an instance method call (C.m()
) or a constructor call (new C()
), the corresponding expression tree node has a child node for this
.
Instance method or constructor call nodes in expression trees have a child labeled "this"
Instance method or constructor call nodes in expression trees have a subtree determining the value of "this"
CorrectionHere is what's right.
An expression like new C()
consists of one node “new C()“. An expression like o.m()
(an instance method invocation) consists of two nodes, “C.m()” for the method invocation, and “o” as the implicit parameter passing the object on which to invoke the method.
While it is true that in the body of the constructor or instance method we will have a this
available, this
is equivalent to a “formal parameter”, but what we need to show in the expression tree is the “actual parameter” (in the case of the instance method invocation above, the “actual parameter” is “o”).
Note that in the specific situation where an instance method calls another instance method on the same object, there indeed will be a “this” node as a child of the call to that other method:
public class C {
public void a() {
this.b(); // the expression tree node "C.b()" will have "this" as child
C other = new C();
other.b(); // the expression tree node "C.b()" will not have "this" as child
}
public void b() {
}
}