Method Invocation
The syntax of a standard Java object method invocation is:
[result] = ObjectName.method [(parameters)]; |
The equivalent COBOL syntax is:
[SET result TO] ObjectName:>method [(parameters)] |
Where:
• ObjectName can be:
a. the name of a data-item that contains the object reference, if we’ve created a new instance of the object (e.g. as shown above with java.io.BufferedReader)
b. the logical-class-name as defined in the REPOSITORY, if we’re invoking a static method (e.g. methods in the class "java.lang.String")
• result can be any COBOL data-item that is of suitable type to receive the method's return value.
NOTE: While ObjectName is not case sensitive because it is COBOL data-item, the name of the method is case sensitive because Java language is case sensitive.
The following Java syntax:
[ObjectType] resultingObjectName = ObjectName.method [(parameters)]; |
is translated to COBOL as:
SET resultingObjectName TO ObjectName:>method [(parameters)] [AS ObjectType] |
• [AS ObjectType] is not always necessary. In most cases the isCOBOL Compiler automatically performs the proper type cast while compiling the OOP statement.
Note: isCOBOL doesn’t support autoboxing, you can’t pass native data types where Object are required. For example, consider the following constructor:
With Java (starting from version 1.5) you’re allowed to call the method in this way:
int i = 0; long l = 2; myMethod (i, l); |
With isCOBOL you need to use java.lang objects instead:
[...] configuration section. repository. class JInt as "java.lang.Integer" class JLong as "java.lang.Long" [...] procedure division [...] myMethod (JInt:>new(0), JLong:>new(2));; [...] |