【发布时间】:2020-04-25 16:36:18
【问题描述】:
我实际上是在尝试跟踪 Account 类的转移次数。 在此处阅读文档:https://www.eclipse.org/aspectj/doc/released/progguide/language-anatomy.html 在幻灯片 48 和 49 上:https://www.eclipse.org/aspectj/doc/released/progguide/language-anatomy.html
这些告诉我我应该能够做这样的事情:
public aspect LoggingAspect {
private int Account.transferCount = 0;
private int Account.getTransferCount() {
return transferCount;
}
pointcut firstTransfer(Account s, double amount):
withincode(public void transfer (int, int, double))
&& call(public boolean withdraw(int,double))
&& target(s)
&& args(amount);
boolean around(Account s, double amount):
firstTransfer(s, amount){
s.transferCount++; // Not recognized
if (s.getTransferCount() == 0) { // Not recognized
System.out.println("50% markup");
return s.deposit(amount*.5);
}
return false;
}
}
但是,正如上面代码中所注释的那样,字段不会被识别为存在于方面内的类中。我做错了什么?
我得到的错误是:transferCount cannot be resolved or is not a field
【问题讨论】: