每当调用其他方法时都调用一个方法 [英] Call a method any time other methods are called

查看:70
本文介绍了每当调用其他方法时都调用一个方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使每次调用方法时都会被调用的超级方法",即使对于未定义的方法也是如此?像这样:

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 onStart() {
    System.out.println("Start");
}

public void onEnd() {
    System.out.println("End");
}

public SuperMethod superMethod() {
    System.out.println("Super");
}

// "Start"
// "Super"
onStart();

// "End"
// "Super"
onEnd();

// "Super"
onRun();

编辑-细节:我有一个库,它会进行很多更新,并且每次更新都变得晦涩难懂.为了简化我的工作流程,我正在使程序自动更新库(需要执行我想做的事情,我不会具体说明原因,但是我的程序可以与将来的更新一起使用),并且我有混淆映射从库中下载,我想制作一种名为 Library 的代理,然后当我调用 Library.getInstance()时,它将获得的混淆映射> getInstance()并调用库方法 getInstance() abz ,因为它已映射到当前时间.

Edit - Specifics: I have a library that updates a lot and gets reobfuscated on each update. To make my workflow easier I am making my program automatically update the library (required to do what I want it to do, I won't go that specific on why, but my program will work with future updates) and I have the obfuscation mappings download with the library, I want to make a sort of proxy called Library for example and then when I call Library.getInstance() it will get the obfuscation mapping for getInstance() and call the library's method getInstance() or abz as it is mapped to at this current moment in time.

推荐答案

以下是使用

输出:

Start
super duper
End
super duper
[onRun is not defined]
super duper

这篇关于每当调用其他方法时都调用一个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆