Fujitsu J Adapter Class Generator Portable Generator User Manual


 
Chapter 3. Developing Programs 25
An example of referencing the class variable AM_PM_FIELD (static field) of the
DateFormat class is shown below:
...
REPOSITORY.
CLASS J-DateFormat AS "java-text-DateFormat"
...
WORKING-STORAGE SECTION
01 FMT-Type PIC S9(9) COMP-5.
...
PROCEDURE DIVISION.
...
MOVE JF-AM_PM_FIELD OF J-DateFormat TO FMT-Type.
...
Comparing Object References
COBOL uses "=" to check whether multiple object references point to the same
object. To check whether the Java objects pointed to by the adapter objects are the
same, COBOL uses the J-EQUALS method of the adapter class instead of "=". The
adapter class always has the J-EQUALS method.
An example of comparing two Date objects is shown below. The condition is met
when Date-1 and Date-2 point to the same Java object.
...
REPOSITORY.
CLASS J-Date AS "java-util-Date"
...
WORKING-STORAGE SECTION
01 Date-1 OBJECT REFERENCE J-Date.
01 Date-2 OBJECT REFERENCE J-Date.
01 rst PIC 1.
...
PROCEDURE DIVISION.
...
INVOKE Date-1 "J-EQUALS" USING CONTENT Date-2 RETURNING rst.
IF rst = B"1" THEN
Condition met
...
Assignment to a Subclass
COBOL uses AS to assign an object to a subclass. However, it uses the J-NARROW
method instead of AS to assign an adapter object. The adapter class always has the
J-NARROW method.