setField()
The javaLib.setField() system function sets the value of a field in a local Java™ object or class. To accomplish this, EGL invokes the local Java™ "set" method for the field.
For more about the EGL Java™ object space in which javaLib.setField() and similar functions operate, see "Java™ access functions." EGL maintains this method of Java™ access for compatibility with earlier versions. For new code, use the more powerful ExternalType syntax; for more information, see "ExternalType part."
Syntax
javaLib.setField(
identifierOrClass javaObjId in,
field STRING in,
value JavaType in)
- identifierOrClass
- This case-sensitive argument is one of the following entities:
- A Java™ objID, to set the value of a field in a local Java™ object.
- A string representing a class name, to set a field value in a Java™ class.
Input can be any variable or expression that is assignment compatible with the STRING type. If you specify an identifier of an object, the identifier must be cast to objID, as in a later example. EGL strips single- and double-byte blanks from the beginning and end of the argument value.
- field
- The case-sensitive name of the field to change. Input can be any variable or expression that is assignment compatible with the STRING type. Single- and double-byte blanks are stripped from the beginning and end of the string.
- value
- The value itself. A cast might be required; see "Mapping EGL primitives
to Java™." The Java™ type-conversion rules are in effect. No
error occurs, for example, if you assign a short to a field that is
declared as an int.A value of an EGL external type is valid, as shown here:
SharedResourcePowerServer srps = JavaLib.getSharedResourcePowerServer(); JavaLib.setField("myId" as "objID:java", "myField", srps);
Example
The following example sets the field myField in
the object identified by myId to the value in myNumField.
javaLib.setField("myId" as "objID:java", "myField",
myNumField as "java:short");
Error considerations
If the v60ExceptionCompatibility program property is not set, or is set to NO, an exception causes EGL to throw a JavaObjectException. Other errors cause EGL to throw a RuntimeException.
If the v60ExceptionCompatibility program property is set to YES, an error during processing of javaLib.setField() can set sysVar.errorCode to a value listed in the next table.
| Value in sysVar.errorCode | Description |
|---|---|
| 00001000 | An exception was thrown by an invoked method or as a result of a class initialization |
| 00001001 | The object was null, or the specified identifier was not in the object space |
| 00001002 | A public method, field, or class with the specified name does not exist or cannot be loaded |
| 00001003 | The EGL primitive type does not match the type expected in Java™ |
| 00001007 | A SecurityException or IllegalAccessException was thrown during an attempt to get information about a method or field; or an attempt was made to set the value of a field that was declared final |
| 00001009 | An identifier rather than a class name must be specified; the method or field is not static |