Community
Participate
Working Groups
sample code from http://www.eli.sdsu.edu/courses/spring03/cs683/notes/aspectJSyntax/aspectJSyntax .html#Heading2 public class Hello { public static void main(String[] args ) { System.out.println("Hello"); } } public aspect HelloAspect { before() : call(void main(String[])) { System.out.println( "Advice"); } } Instead of output as Advice Hello The output is Hello If the aspect is changed to public aspect HelloAspect { before() : call(void *(*)) && !within(HelloAspect) { System.out.println( "Advice"); } } then the correct output is produced Advice Hello I tried to put advice on other static methods and the advice was picked up. Is the advice supposed to work in this way? I am using the latest 1.1.1 AJDT plugin for Eclipse.
This is the correct behavior. call(void main(..)) matches every call to the main method, but in this case the call to main is happening from the JVM and is not visible to the compiler. If you put advice on execution(void main(..)) that will run whenever the main method starts executing regardless of where it is called from.