数组元素设置切入点。有解决方法吗?
我刚刚读到不可能在单个数组元素上定义切入点(bug链接)。考虑到我确实需要检测数组元素修改,我想知道是否有针对此类问题的解决方法(模式或其他)。
类似于这篇文章中描述的
public class FieldPointcuts {
static int ar[];
public static void main(String[] args) {
ar = new int[] {100}; //set
ar[0] = 200; //get
}
}
内容建议
before(int i, Object s, Object[] a):
arrayset() && args(i, s) && target(a)
{
System.out.println (" Arrayset:["+i+"/"+(a.length-1)+"] = "+s) ;
}
提前致谢。
I just read that it is not possible to define a pointcut on a single array element (bug link). Considering I really need to detect an array element modification, I would like to know if there is any workaround for this kind of problem (a pattern or something).
Something like what is described in this article
public class FieldPointcuts {
static int ar[];
public static void main(String[] args) {
ar = new int[] {100}; //set
ar[0] = 200; //get
}
}
and advice
before(int i, Object s, Object[] a):
arrayset() && args(i, s) && target(a)
{
System.out.println (" Arrayset:["+i+"/"+(a.length-1)+"] = "+s) ;
}
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,我想不出任何可行的方法。我能想到的最好的办法是使用列表而不是数组,但如果您要编织到第三方代码中,这是不可能的。
Unfortunately, there is nothing I can think of that will work. The best that I can think of would be to use Lists instead of arrays, but if you are weaving into third party code, this would not be possible.