Call a method any time other methods are called

后端 未结 5 460
傲寒
傲寒 2021-01-04 11:19

Is there any way to make a sort of \"supermethod\" that is called every time a method is called, even for non-defined methods? Sort of like this:

public void         


        
5条回答
  •  攒了一身酷
    2021-01-04 11:54

    Java doesn't really allow magic like this. In order for a call to happen, it has to appear within your (compiled) code. So the answer is no, not without explicitly adding a call to the relevant methods. However, you can hide that somewhat by using a preprocessor or runtime code generation.

    I think AspectJ might be what you want.

提交回复
热议问题