【问题标题】:Is there a way to monitor methods so that another method is executed elsewhere in the code?有没有办法监控方法,以便在代码的其他地方执行另一种方法?
【发布时间】:2023-03-11 10:34:01
【问题描述】:

谁能帮助我并解释如何最好地观察一种方法。这意味着当某个方法被执行时,整个系统应该在另一个点内部重新计算,例如。例如上传文件时也是如此,则应在后台触发某些计算。

Observer 已被弃用,我认为 PropertyChangeListener 对我没有帮助。

有没有人知道如何在 Java 中映射这种情况?

谢谢

【问题讨论】:

  • 看看AspectJ

标签: java design-patterns observable propertychangelistener


【解决方案1】:

在我看来有两种方法:

  1. 用户方面J。喜欢这两个例子:12

  2. 创建您自己的注释。然后你可以接收你想要触发的方法作为参数。像这样的:

     @MyCustomTriggerAnnotation(methodsToBeTriggered= {methodA, methodB})
     public void test(){
    
     }
    

【讨论】:

    猜你喜欢
    • 2014-05-08
    • 1970-01-01
    • 2020-03-11
    • 2015-05-04
    • 1970-01-01
    • 2020-11-06
    • 2022-04-27
    • 2017-02-22
    • 1970-01-01
    相关资源
    最近更新 更多