This section describes how to use C++ proxy classes.
To declare C++ proxy class variables, you can use:
The C++ default constructor; for example, the following code lines each create an instance of the A_B_MyClass proxy class:
A_B_MyClass mcl; A::B::MyClass mcl; // Using namespaces // Using namespaces after introducing // “using namespace A::B” within the current scope MyClass mcl;
The default constructor sets the values of the class variables to null.
The C++ copy constructor; for example, the following code lines each create a proxy class variable called mc2, which is a copy of mc1:
A_B_MyClass mc2(mc1); A_B_MyClass mc2(mc1.getMyObject());
The values of mc2 variables are set to the values of mc1 variables.
To assign proxy class variables, you can use any of the following statements, where mc1 and mc2 are both instances of the same proxy class.
From another object:
mc2 = mc1
From an expression:
mc2 = mc1.getMyobject();
To set the value to null:
mc2 = java_null
You can compare proxy class references to check for null or for equality.
Check whether the value of the proxy class variable is null:
if (mc1 == java_null)
Check whether mc1 and mc2 refer to the same Java object:
if (mc1 == mc2)
Java constructors are mapped to C++ global functions whose names are created by adding the prefix “new” to the name of the constructor. For example, if Java class A.B.MyClass has a default constructor, you can call the C++ proxy class method as follows:
mc1 = new_A_B_MyClass(); mc1 = A::B::new_MyClass(); // when using namespaces
If Java class A.B.MyClass has a constructor that takes an int parameter, you can call the C++ proxy class method as in this example:
mc1 = new_A_B_MyClass(123);
If your C++ compiler does not support namespaces, you might want to define a few macros for commonly accessed classes and methods; for example:
#define null java_null #define String java_lang_String #define new_String new_java_lang_String