CNI array syntax

Bryce McKinlay bryce@albatross.co.nz
Thu Mar 29 19:25:00 GMT 2001


Has a more natural syntax for creating java arrays from CNI ever been
considered?

Today I wanted to do the equivilant of "new java.io.File[1]" in C++.
The code for this (afaik) is quite ugly:

myfile = reinterpret_cast <JArray< ::java::io::File *>*>
(JvNewObjectArray (1, &java::io::File::class$, f));

But it should be able to be much more cleanly expressed as:

myfile = new JArray<java::io::File *> (1);

After a quick look it seems like some hacking of the
TYPE_FOR_JAVA logic in the C++ compiler would be required, as well as
adding special recognition for JArray types to C++'s "new" code and
calling _Jv_NewObjectArray instead of _Jv_AllocObject. I don't see
anything that would make this particularly difficult though. Just a
thought.

regards

  [ bryce ]




More information about the Java mailing list