如何通过AspectJ为被调用的方法声明变量?

时间:2016-09-05 09:22:03

标签: java aspectj

我知道AspectJ可以声明inter-type,但我想声明一个变量内部的TestMain.test方法,因此只有那个方法可以得到它,但所有其他方法都无法获取变量。

public aspect GetParams {
    public int TestMain.anInt = 2; // I know this is accessed in the whole scope of a TestMain instance
    // How to declare a local variable only for TestMain.test
}

public class TestMain {

    public void test(int a)
    {
        System.out.println(anInt);
    }

    public void test2() {
        // cannot accessed here
    }
}

---------------更新------------------

我描述了我想要的东西。

该场景是针对Jersey API的一种方法,我希望在方法中获得一个映射器,其中包含所有参数和API所需的值。因此,我希望自动完成此工作的方法有一个注释。

0 个答案:

没有答案