Using proxy classes

This section describes how to use C++ proxy classes.

Declaring variables

To declare C++ proxy class variables, you can use:

Assigning 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.

Comparing references

You can compare proxy class references to check for null or for equality.

Calling constructors

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);

Defining macros

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