Category: Proxy usage
How do I create an array instance?
Let's first discuss how array types differ between the two languages.
You have to use the generated or supplied array proxy type and use parentheses rather than square brackets in the instantiation, for example:
StringArray arr = new StringArray( 16 );
arr[ 0 ] = "first"; arr[ 15 ] = "last";
.NET proxy types for Java array types are not .NET array types. In .NET you cannot generate any compilable source code that extend the .NET Array type. Consequently, our proxy array types just behave mostly like .NET arrays without being .NET array types.
There is an explicit conversion path between an instance of a .NET array of the type and the corresponding Java array type, i.e. string[] and StringArray:
string narr[] = new string[] { "1", "2", "3" };
StringArray arr = narr;
The mapping between Java and .NET proxy array types is fairly straightforward:
| Java type | .NET proxy type |
|---|---|
| boolean[ ] | Codemesh.JuggerNET.boolArray |
| byte[ ] | Codemesh.JuggerNET.byteArray |
| char[ ] | Codemesh.JuggerNET.charArray |
| double[ ] | Codemesh.JuggerNET.doubleArray |
| float[ ] | Codemesh.JuggerNET.floatArray |
| int[ ] | Codemesh.JuggerNET.intArray |
| long[ ] | Codemesh.JuggerNET.longArray |
| short[ ] | Codemesh.JuggerNET.shortArray |
| java.lang.Object[ ] | Java.Lang..ObjectArray |
| java.lang.Object[ ][ ] | Java.Lang.ObjectArrayArray |
| Foo[ ][ ][ ] | FooArrayArrayArray |
The primitive array types are provided as part of the runtime library; the object array types are provided via proxy types that follow an obvious naming policy.
