You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 17, 2022. It is now read-only.
The first signature accepts `string` for `elementClassName`. This option is useful when you have to create Java array of primitive types (e.g. `char`, `boolean`, `byte`, `short`, `int`, `long`, `float` and `double`). It is also useful when you have to create Java jagged arrays. For this scenario `elementClassName` must be the standard JNI class notation. Here are some examples:
129
-
```javascript
129
+
```JavaScript
130
130
// equivalent to int[][] jaggedIntArray2 = new int[10][];
131
131
var jaggedIntArray2 =Array.create("[I", 10);
132
132
@@ -137,14 +137,47 @@ var jaggedBooleanArray3 = Array.create("[[Z", 10);
137
137
var jaggedObjectArray4 =Array.create("[[[Ljava.lang.Object;", 10);
138
138
```
139
139
The second signature uses `javaClassCtorFunction` which must the JavaScript constructor function for a given Java type. Here are some examples:
140
-
```javascript
140
+
```JavaScript
141
141
// equivalent to String[] stringArr = new String[10];
142
142
var stringArr =Array.create(java.lang.String, 10);
143
143
144
144
// equivalent to Object[] objectArr = new Object[10];
145
145
var objectArr =Array.create(java.lang.Object, 10);
146
146
```
147
147
148
+
### Array of Primitive Types
149
+
The automatic marshalling works only for cases with arrays of objects. In cases where you have a method that takes an array of primitive types, we need to convert as follows:
150
+
```Java
151
+
publicstaticvoid myMethod(int[] someParam)
152
+
```
153
+
Then we need to invoke it as follows:
154
+
```JavaScript
155
+
let arr =Array.create("int", 3);
156
+
arr[0] =1;
157
+
arr[1] =2;
158
+
arr[2] =3;
159
+
160
+
SomeObject.myMethod(arr); // assuming the method is accepting an array of primitive types
161
+
```
162
+
163
+
### Two-Dimensional Arrays of Primitive Types
164
+
165
+
The above scenario gets more tricky with two-dimensional arrays. Consider a Java method that accepts as an argument a two-dimensional array:
The JavaScritp marshaled code will look like this:
170
+
```JavaScript
171
+
let arr =Array.create("[Ljava.lang.Integer;", 2);
172
+
let elements =Array.create("java.lang.Integer", 3);
173
+
elements[0] =newjava.lang.Integer(1);
174
+
elements[1] =newjava.lang.Integer(2);
175
+
elements[2] =newjava.lang.Integer(3);
176
+
arr[0] = elements;
177
+
178
+
SomeObject.myMethod(arr); // assuming the method is accepting a two-dimensional array of primitive types
179
+
```
180
+
148
181
### Null
149
182
The Java [null literal](http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.7) (or null pointer) is projected to JavaScript [Null](http://www.w3schools.com/js/js_typeof.asp):
0 commit comments