Next: , Previous: , Up: About CNI   [Contents][Index]


11.4 Reference types

A Java reference type is treated as a class in C++. Classes and interfaces are handled this way. A Java reference is translated to a C++ pointer, so for instance a Java java.lang.String becomes, in C++, java::lang::String *.

CNI provides a few built-in typedefs for the most common classes:

Java typeC++ typenameDescription
java.lang.ObjectjobjectObject type
java.lang.StringjstringString type
java.lang.ClassjclassClass type

Every Java class or interface has a corresponding Class instance. These can be accessed in CNI via the static class$ field of a class. The class$ field is of type Class (and not Class *), so you will typically take the address of it.

Here is how you can refer to the class of String, which in Java would be written String.class:

using namespace java::lang;
doSomething (&String::class$);