getField()

The system function JavaLib.getField returns the value of a specified field of a specified object or class. JavaLib.getField is one of several Java™ access functions.

  JavaLib.getField(
    identifierOrClass javeObjIdOrClass in,
    field STRING in)
  returns (result anyJavaPrimitive)
result
The result field is required and receives 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 field must be a numeric data type. The characteristics do not need to match the value; for example, a float may be stored in a return variable that is declared with no decimal digits. For details on handling overflow, see VGVar.handleOverflow and sysVar.overflowIndicator.
  • If the received value is a boolean, the result field must be of a numeric primitive type. The value is 1 for true, 0 for false.
  • If the received value is a byte array, the result field 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 details on mismatched lengths, see Assignments.

  • If the native Java method does not return a value or returns a null, error 00001004 occurs, as listed later.
identifierOrClass
This argument is one of the following entities:
  • An identifier that refers to an object in the object space; or
  • The fully qualified name of a Java class.

This argument is either a string literal or a variable of type CHAR, DBCHAR, MBCHAR, STRING, or UNICODE. If you are specifying an identifier of an object, the identifier must be cast to objID, as in a later example. If you intend to specify a static field in the next argument, it is recommended that you specify a class in this argument.

EGL strips single- and double-byte blanks from the beginning and end of the argument value, which is case sensitive.

field
The name of the field to read.

This argument is either a string literal or a variable of type CHAR, DBCHAR, MBCHAR, STRING, or UNICODE. Single- and double-byte blanks are stripped from the beginning and end of the string, which is case sensitive.

An example is as follows:
  myVar = JavaLib.getField( (objId)"myID", "myField" );

An error during processing of JavaLib.getField 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
00001004 The method returned null, 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 return variable
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

Related concepts

Related tasks
Syntax diagram for EGL statements and commands

Related reference
Assignments
BIN and the integer types
EGL library JavaLib
Exception handling

invoke()
isNull()
isObjID()
qualifiedTypeName()
remove()
removeAll()
setField()
store()
storeCopy()
storeField()
storeNew()

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.