数组元素设置切入点。有解决方法吗?

发布于 2024-09-30 10:43:39 字数 692 浏览 1 评论 0原文

我刚刚读到不可能在单个数组元素上定义切入点(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱着落日 2024-10-07 10:43:39

不幸的是,我想不出任何可行的方法。我能想到的最好的办法是使用列表而不是数组,但如果您要编织到第三方代码中,这是不可能的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文