我想在使用本机方法之前检查它的实现,但我不知道如何。
If a native method of a class isn't defined for your platform, the classloader will throw an java.lang.UnsatisfiedLinkError
. So your test could be
try {
Class.forName("your.class.with.NativeCode");
} catch (UnsatisfiedLinkError e) {
// the implementation for the methods cannot be linked.
}
This code would need to be in an unrelated class that doesn't have any direct dependency to the class with native code. Otherwise this class cannot be loaded as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.