我有一个场景,我想运行我无法控制的代码.我想阻止在该代码中使用任意标准JDK方法(例如,我想阻止在任何String对象上使用lastIndexOf()方法).
如果使用禁用方法,则应导致运行时异常.
我怀疑这可能是自定义类加载器,但我不知道如何处理这个问题.我遇到的部分问题是String是一个无法扩展的最终类.
例:
//I control this code
int result = SomeClass.method("foo") //I don't control SomeClass
//A valid implementation of SomeClass.method()
int method(String in) {return 1;}
//An invalid implementation of SomeClass.method()
int method(String in) {return in.lastIndexOf("o");}
//the above should throw an error at run time when called from my code
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
193 次 |
| 最近记录: |