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

前端 未结 2 723
暗喜
暗喜 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.

    0 讨论(0)
  • 2021-01-14 01:12

    I think you are looking for an aspect-oriented programming framework such as AspectJ, JBoss AOP or Spring AOP.

    The decoration of the Person method by the Robot method will happen during construction of the Person instance, but you will need to use a factory class provided by the AOP container instead of new.

    0 讨论(0)
提交回复
热议问题