我想知道是否有办法从main函数中获取变量并在方面中使用它。我知道before()
和after()
建议会在methodeOne
之前和之后执行,但他们如何获得VAR1
和/或VAR2
?
public class AOPdemo {
public static void main(String[] args) {
AOPdemo aop = new AOPdemo();
aop.methodeOne(5);//Call of the function wrapped in the aspect
int VAR1;
//VAR1 variable im trying to send to the aspect
}
public void methodeOne(int VAR2){
//VAR2 another variable i'm trying to send to the aspect
System.out.println("method one");
}
}
public aspect myAspect {
pointcut function():
call(void AOPdemo.methode*(..));
after(): function(){
int VAR1;//Trying to get this variables
int VAR2;
System.out.println("aspect after...");
}
before(): function(){
System.out.println("...aspect before");
}
}