How to make a method be called passive before invoke a method

前端 未结 2 792
暗喜
暗喜 2021-01-14 00:11

Like so : a class has a method called sayHello() . When a instance of the class call the sayHello(), a method in another class is called automatic before the sayHello() is

2条回答
  •  春和景丽
    2021-01-14 00:52

    Check AspectJ, and aspect-oriented programming framework. It will allow you to do something similar.

    You see, in order to make this happen, you class should be managed by some container which instantiates your objects and makes proxies of them.

    AspectJ has an alternative by plugging some "magic" into the VM.

提交回复
热议问题