【发布时间】:2018-01-26 15:39:44
【问题描述】:
假设我有以下类(或者也可以使用接口来完成?):
class MyCustomClass {
boolean myCustomMethod(int a, int b){}
}
还有以下字符串:
Math.abs(a - b) >= 10;
有没有办法通过 Byte Buddy 将字符串中的代码注入 MyCustomClass 的新子类,在方法 myCustomMethod 中?即使String之前用ANTLR处理过?
所以我明白了
class MyCustomClass_SubClassInstance extends MyCustomClass {
// I know that with ByteBuddy, all this "ceremonial" code is not needed.
boolean myCustomMethod(int a, int b){
Math.abs(a - b) >= 10; // Injected code from the string
}
}
【问题讨论】:
-
这是怎么回事:Math.abs(a - b) >= 10;一个字符串?
-
不,诠释。我的问题确实需要澄清。
-
我很欣赏超级快速的回归 ;-)
-
好的,再次感谢。现在,如果 Dalvik 可以的话,我必须在 Android 中找到一种方法。
标签: java android antlr4 byte-buddy