potato
potato

Reputation: 11

How to check if an java native method is implemented?

I want to check implementation of the native method before use it, but I don't know how.

Upvotes: 0

Views: 426

Answers (1)

Harald Gliebe
Harald Gliebe

Reputation: 7564

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.

Upvotes: 1

Related Questions