【发布时间】:2013-04-17 09:45:03
【问题描述】:
我已经看到 here 和 here 不能在 android 中覆盖本地方法,但我想知道我是否可以让一个类声明一些本地方法,然后用另一个类声明一些额外的本地方法来扩展它.
我的情况如下:
public class A{
public native int aMethod();
}
public class B extends A{
public native int bMethod();
static {
try{
System.loadLibrary("MyNativeLibraryWithBothaMethodAndbMethod");
}
catch (java.lang.UnsatisfiedLinkError e){
System.out.println (e);
}
}
}
public class MyActivity extends Activity {
private B bClass;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
bClass = new B();
bClass.aMethod();//Working fine
bClass.bMethod();//UnsatisfiedLinkError
}
}
库加载没有问题,调用了第一个方法,但没有调用第二个。
如果我将 bMethod 从 B 移动到 A,一切正常。
将 System.loadlibrary() 从 B 移动到 A 似乎没有效果。
是否可以使用额外的本地方法扩展 A 类?
【问题讨论】:
标签: android inheritance native extends