user3324147
user3324147

Reputation: 31

Returning a class instance in an (aspect)interface method

I am implementing an interface from an an aspect

declare parents: SomePackage.AClass+ extends InterfaceBelow

public interface InterfaceBelow() {
        //bunch of methods
}

I want a method which should return the class/instance implementing the interface itself. Something such as adding a method to the interface public Object getSelf() and then use AspectJ to implement it like this:

public InterfaceBelow.getSelf()
{
     //how to return the instance implementing the interface
}

I need to do it in the aspect not from the class and then {return this;}

Upvotes: 3

Views: 121

Answers (1)

aepurniet
aepurniet

Reputation: 1727

have InterfaceBelow.getSelf() return null. then create an around pointcut around that method. the pointcut can capture the target of the method invocation. return that instead.

Upvotes: 1

Related Questions