Coding With C++ Proxy Types
A Brief History Lesson
Java started out as a language that addressed the perceived (and real) weaknesses of C++ in the areas of complexity, memory management, and library functionality. Many people thought that it was just too easy to write buggy code in C++. Pointers, memory management, and advanced preprocessor features were identified as some of the main culprits and Java simply did away with them.
At the same time, Java's inventors added a lot of library types
that provided built-in functionality that most C++ developers would have killed for in 1999. A lot of the more advanced features that
C++ developers rely on today (templates, operator overloading, the entire std
library, boost, etc.) were not yet available
to C++ developers in the early years of Java.
In those early days, just having access to the Java collection types from C++ could make a pretty strong business case because teams either licensed expensive collection libraries or had to write and debug their own. Today, C++ developers eye Java types mostly from an integration angle. They are usually forced to consume a Java business API from their C++ application. How can they do that?
Proxy Types to the Rescue
In general, the C++ proxy types are as usage-compatible with their corresponding Java types as we can make them. This means that you can take an application that is written in Java and replicate it by writing C++ code that is almost a one-to-one mirror image of the Java code.
This is made possible by Java being, in general, a simpler language than C++. It would be extremely hard if not impossible to go in the other direction and express all of C++'s language features in easy-to-use Java.
A C++ proxy type for a Java type is much more than just a C++ type that has the same name as its underlying Java type: it has the expected type inheritances; it has fields that can be used as fields without having to worry about the lifecycle of returned objects; it has methods that take strongly-typed arguments and return strongly-typed results; it has framework constructors, destructors, assignment operators, and much more to make sure that the proxy type can be used just as you would expect.
We encourage you to go through the tutorial and maybe also the pitfalls page to get a feeling for what it is like to write C++ code using proxy types.