getField()

The javaLib.getField() system function returns the value of a specified field within a specified Java™ object or class in the EGL Java object space.

For more about the EGL Java object space in which javaLib.getField() 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.getField(
    identifierOrClass javeObjIdOrClass in,
    field STRING in)
  returns (result anyJavaPrimitive)
identifierOrClass
Any of the following entities can serve as this argument:
  • A Java objID, to get the value of an object field.
  • A case-sensitive string representing a class name, to get the value of class field. Single- and double-byte blanks are stripped from the beginning and end of the string.
field
The case-sensitive name of the field to read. 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.
result
The result is the value of the field specified in the second argument. The following cases apply:
  • If the received value is a BigDecimal, BigInteger, byte, short, int, long, float, or double, the result variable must be a numeric data type. The characteristics do not need to match the value; for example, a float can be stored in a return variable that is declared with no decimal digits. For details on handling overflow, see the sysVar topic overflowIndicator.
  • If the received value is a Boolean, the result variable must be a BOOLEAN or numeric primitive type. For numeric variables, the value is 1 for true, or 0 for false.
  • If the received value is a byte array, the result variable must be of type HEX. For details on mismatched lengths, see "Assignments."
  • If the received value is a String or char, the result field must be of type CHAR, DBCHAR, MBCHAR, STRING, or UNICODE:
    • If the result field is of type MBCHAR, STRING, or UNICODE, the received value is always appropriate
    • If the result field is of type CHAR, problems can arise if the received value includes characters that correspond to DBCHAR characters
    • If the result field is of type DBCHAR, problems can arise if the received value includes Unicode characters that correspond to single-byte characters

    For more information on mismatched lengths, see Assignments.

Example

The following example shows the getField() function, with myID cast as objID:

  myVar = javaLib.getField("myID" as "objID:java", "myField");

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.getField() can set sysVar.errorCode to a value listed in the next table.

Table 1. getField() error codes
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 had a null value, 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.
00001004 The method returned a null value, the method does not return a value, or the value of a field was null.
00001005 The returned value does not match the type of the variable which you assigned it.
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.

Feedback