Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;}

like image 721
user3324147 Avatar asked May 13 '26 06:05

user3324147


1 Answers

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.

like image 145
aepurniet Avatar answered May 15 '26 21:05

aepurniet