Page 2 of 2
public void convolve() {
if (_native)
nativeConvolve();
else
fallbackConvolve();
}
private native void nativeConvolve();
private void fallbackConvolve() {
...
}
In this example, a convolution operation can be performed either by native method nativeConvolve or by fallback method fallbackConvolve. The distinction between these two methods is irrelevant to the class user, who simply invokes convolve to perform the operation. If the dynamic library has been installed, the user gets the benefits of faster execution; if the
dynamic library is unavailable, the operation can still be carried out, albeit more slowly.
That's all there is to it! Once you've written and compiled your class, you add the native method support in the normal way. (See the current version of Sun's Java Tutorial for an explanation of how to do this.)