private native int foo(double bar);
So, eventually this has to call a C++ function for its implementation. In particular, it'll end up calling a function with a name something like:
Java_MyClass_foo
What happens if there are multiple native foo methods with different signatures? Complications. If you do it, Java will add type information into the name of the method it looks for. But it is simply easier if you stick to non-overloaded methods.
public int foo(double bar) {
return foo0(bar);
}
private native int foo0(double bar);
foo0
has been given a unique name, there should never be a reason to add another foo0
. This keeps the implementation of the C++ simple, it never has to deal with mangled names. Even if foo eventually gains an overload, it will call foo1
instead of foo0
and the C++ JNI implementation won't have to deal with the extra complications of overloading.