Ellesmess Glain
Ellesmess Glain

Reputation: 115

How to access class members from advice in AspectJ?

I have this piece of code:

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.CodeSignature;

aspect SomeAspect {
    void around(): call(void jy.run()) {
        System.out.println(>> here I want access jy's final field a<<);
    }
}

How to access local field of class jy in aspect's code?

Upvotes: 1

Views: 748

Answers (1)

Ellesmess Glain
Ellesmess Glain

Reputation: 115

By using the target pointcut:

void around(jy t): target(t) && call(void run()) {
    System.out.println(t.someField);
}

Upvotes: 1

Related Questions