Reputation: 1995
Ok so I'm written some code that will need operation overloading for the syntax to have good readable. Right now I'm using Java to write the program. But I though hey c++ got operation overloading and android supports both Java and c++ programming, so maybe I can create the classes I need to have operation overloading in c++ and the use the in the Java code. What I'm wonder is if this will work, or will the restriction in Java for operation overload prevent me from doing this?
Upvotes: 1
Views: 514
Reputation: 41281
Yes, but not in a way how you would expect. You would use JNI to call into NDK functions which may internally use operator overloading. However, any Java calls you make in from native methods will call into a C++ function with a specific name corresponding to the class and name of the declared native function.
For example, the following Java declaration:
package com.foo;
class Obj {
int i;
native void doCalc();
}
would match the following C++ declaration:
JNIEXPORT void JNICALL
Java_com_foo_Obj_doCalc(JNIEnv * env, jobject obj)
{}
which is clearly not an operator overload. That function itself, can use overloaded operators in its execution.
Upvotes: 3