是否可以在运行时重写方法? [英] Is it possible to override a method at runtime?
本文介绍了是否可以在运行时重写方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在运行时是否有重写方法的方法?即使需要从该实例动态创建子类?
Is there anyway to override a method at run time? Even if it requires dynamically creating a subclass from that instance?
推荐答案
使用纯Java,否.
使用 ByteBuddy (首选), asm , cglib 或
With ByteBuddy(preferred), asm, cglib or aspectj, yes.
In plain Java, the thing to do in a situation like that is to create an interface-based proxy that handles the method invocation and delegates to the original object (or not).
这篇关于是否可以在运行时重写方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文