| www.delorie.com/gnu/docs/gcc/gcj_35.html | search |
![]() Buy the book! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
While in many ways Java is similar to C and C++, it is quite different
in its treatment of arrays. C arrays are based on the idea of pointer
arithmetic, which would be incompatible with Java's security
requirements. Java arrays are true objects (array types inherit from
java.lang.Object). An array-valued variable is one that
contains a reference (pointer) to an array object.
Referencing a Java array in C++ code is done using the
JArray template, which as defined as follows:
class __JArray : public java::lang::Object
{
public:
int length;
};
template<class T>
class JArray : public __JArray
{
T data[0];
public:
T& operator[](jint i) { return data[i]; }
};
|
There are a number of typedefs which correspond to typedefs
from the JNI. Each is the type of an array holding objects
of the relevant type:
typedef __JArray *jarray; typedef JArray<jobject> *jobjectArray; typedef JArray<jboolean> *jbooleanArray; typedef JArray<jbyte> *jbyteArray; typedef JArray<jchar> *jcharArray; typedef JArray<jshort> *jshortArray; typedef JArray<jint> *jintArray; typedef JArray<jlong> *jlongArray; typedef JArray<jfloat> *jfloatArray; typedef JArray<jdouble> *jdoubleArray; |
array. For instance, you can fetch a pointer to the
integers that make up an int[] like so:
extern jintArray foo; jint *intp = elements (foo); |
The name of this function may change in the future.
klass is the type of elements of the array and
init is the initial value put into every slot in the array.
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |