简体   繁体   English

有没有办法替换库类?

[英]Is there a way to replace library classes?

Lets say that a lot of functionality are using methods from this class test.MyClass , but it's very slow and I'd like to code in JNI in hopes of improving the timing... 可以说,很多功能正在使用此类test.MyClass方法,但是它非常慢,我想用JNI编写代码,以期改善时序。

Is there a way to replace test.MyClass so that the library does not need to be changed, but the codes in the library will use the new test.MyClass with native implementations for certain methods from now on? 有没有一种方法可以替换test.MyClass ,而无需更改库,但是从现在开始,库中的代码将使用具有特定方法的本机实现的新test.MyClass It's the classic "PC is fine but the timing for Android is crap" problem. 这是经典的“ PC很好,但Android的时机很糟糕”的问题。

Just create your test.MyClass in the same package/hierarchical structure as the one in the package you want to override. 只需在与要覆盖的包中的包/层次结构相同的包/层次结构中创建test.MyClass The classloader should load your implementation first and if it tries to load the one from other library the load will fail, because there can be only one loaded instance in the classpath. classloader应首先加载您的实现,并且如果尝试从其他库中加载实现,则加载将失败,因为在类路径中只能有一个加载的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM