Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Intertype method declarations and method dispatch

Hi Oliver,
"Call" in this section of the documentation is not referring to the call 
pointcut designator, but to a "method call" that you might write in your 
code (like foo.bar()). The JLS calls these "Method Invocation Expressions" 
to give them their formal name. When you write a line of code like 
"foo.bar()" the compiler has to work out which "bar()" method should 
actually be invoked (dispatched) - which can be complex given overriding, 
overloading, autoboxing, varargs, .... The process of determining the 
target method is known as "resolution'. See section 15.12 of the JLS for 
the full gory details. The AspectJ 5 addition to the rules, as documented 
in the referenced section of the notebook, is that intertype declared 
methods take preference over methods that match only when autoboxing or 
varargs are taken into account.

A simple example:

class A {

  public void methodA(Integer someInt) {...}

}

aspect ITD {

 public void A.methodA(int someInt) {...}

}

public class B {

  public static void main(String[] args) {
     A a = new A();
     a.methodA(5);      // <=== what happens here??
  }

}

and the question is, which method executes when the highlighted line of 
code runs?  According to the rules, it will be A.methodA(int someInt) 
defined within the aspect ITD. This method matches without considering 
autoboxing, whereas the definition of methodA(Integer) in A only matches 
when autoboxing is taken into account.

Regards, Adrian. 

-- Adrian
Adrian_Colyer@xxxxxxxxxx



"Oli B." <boehm@xxxxxxxxxx> 
Sent by: aspectj-dev-bounces@xxxxxxxxxxx
24/04/2005 10:48
Please respond to
boehm@xxxxxxxxxx; Please respond to
AspectJ developer discussions <aspectj-dev@xxxxxxxxxxx>


To
AspectJ developer discussions <aspectj-dev@xxxxxxxxxxx>
cc

Subject
[aspectj-dev] Intertype method declarations and method dispatch






Hello,

I read 
http://www.eclipse.org/aspectj/doc/ajdk15notebook/autoboxing-and-method-dispatch.html 

but have problems to understand it. Autoboxing is only considered during 
runtime, so a normal call pointcut is not affected by it. But what does 
"the target method of a call" mean in this chapter?

Can anybody provide an example for the described method dispatch 
algorithm in this article?

kind regards
Oliver
-- 
Oliver Böhm
http://www.javatux.de

_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev




Back to the top