Java Event Listener to detect a variable change

前端 未结 7 1835
逝去的感伤
逝去的感伤 2021-02-05 14:38

I cannot seem to find an answer anywhere to my question. Is there any event listener which can detect the changing of a boolean or other variable and then act on it. Or is it p

7条回答
  •  天命终不由人
    2021-02-05 15:10

    You can use AOP for that, perhaps AspectJ? Check a few examples here (if you use Eclipse, then using AspectJ is really simple with their plugin).

    For you, you would have a pointcut similar to the one used in the SampleAspect, but one that will only be used when someone makes a new SET to a boolean variable (this doesn't mean that the value has changed, just that someone loaded a value to the variable).

提交回复
热议问题