Java Reference
In-Depth Information
// Let us add a property named z
System.out.println("Adding z = 30 to point in Java... ");
point.setMember("z", 30);
}
public static void arrayTest(ScriptObjectMirror empIds) {
if (!empIds.isArray()) {
System.out.println("Passed in obejct is not an array.");
return;
}
// Get the length proeprty of teh array
int length = ((Number) empIds.getMember("length")).intValue();
System.out.println("empIds received in Java...");
for (int i = 0; i < length; i++) {
int value = ((Number) empIds.getSlot(i)).intValue();
System.out.printf("empIds[%d] = %d%n", i, value);
}
// Let us add an element to the array
System.out.println("Adding empIds[2] = 103 in Java... ");
empIds.setSlot(length, 103);
}
}
Properties of point received in Java...
x = 10
y = 20
Adding z = 30 to point in Java...
In script, after calling the Java method propTest()...
x = 10
y = 20
z = 30
empIds received in Java...
empIds[0] = 101
empIds[1] = 102
Adding empIds[2] = 103 in Java...
In script, after calling the Java method arrayTest()...
empIds[0] = 101
empIds[1] = 102
empIds[2] = 103
Search WWH ::




Custom Search