Where You Can Specify an Object Field

You can use an object field in the following situations:
Free-Form Evaluation
You can use the EVAL operation to assign one Object item (field or prototyped procedure) to a field of type Object.
Free-Form Comparison
You can compare one object to another object. You can specify any comparison, but only the following comparisons are meaningful:
  • Equality or inequality with another object. Two objects are equal only if they represent exactly the same object. Two different objects with the same value are not equal.
    If you want to test for equality of the value of two objects, use the Java™ 'equals' method as follows:
     D objectEquals    PR              N   EXTPROC(*JAVA
     D                                           : 'java.lang.Object'
     D                                           : 'equals')
     C                   IF        objectEquals (obj1 : obj2)
     C                    ...
     C                   ENDIF
  • Equality or inequality with *NULL. An object is equal to *NULL if it is not associated with a particular instance of its class.
Free-Form Call Parameter
You can code an object as a parameter in a call operation if the parameter in the prototype is an object.
Note:
  1. Objects are not valid as input or output fields.
  2. Assignment validity is not checked. For example, RPG would allow you to assign an object of class Number to an object variable defined with class String. If this was not correct, a Java error would occur when you tried to use the String variable.
Figure 1. Object Data Type Example
D Obj             S               O   CLASS(*JAVA
D                                          :'java.lang.Object')
D Str             S               O   CLASS(*JAVA
D                                          :'java.lang.String')
D Num             S               O   CLASS(*JAVA
D                                          :'java.math.BigDecimal')

 * Since all Java classes are subclasses of class 'java.lang.Object',
 * any object can be assigned to a variable of this class.
 * The following two assignments are valid.
C                   EVAL      Obj = Str
C                   EVAL      Obj = Num
 * However, it would probably not be valid to assign Str to Num.