Java callback function for each class method

Is there a way in JAVA to call a callback function for every method of my class without calling the call explicitly

I do not want to do

public void foo()
{
   //some code
   callBackFunction()
} 

I'd like to do

public void foo()
{
   //some code
} 

and then the class recognizes that it should call the callBackFunction () function

+3
source share
4 answers

, " ". Java- ( "DebugProxy", ).

+8

- - - . AspectJ IOC, Spring, .

, "pointcuts", , . (, callbackFunction()) , , .

, , , .

+8

AOP - AspectJ, ,

+1

AOP AspectJ. AspectJ, AOP, Spring .

, , Spring Java Proxies AOP. , , "" / .

, Proxies Spring, ,

public void foo() {
    callbackFunction();
    this.delegate.foo();
}

this.delegate "", foo(), .

...
IFooBar y = new FooBar();   // implements IFooBar
IFooBar x = new FooBarProxy(y);   // also implements IFooBar, but with the callback and delegate
x.foo();  // calls y.foo() implicitly
...
+1

Source: https://habr.com/ru/post/1723933/


All Articles