%THIS(返回本机方法的类实例)
%THIS
%THIS 返回一个对象值,该对象值包含对以其名义调用本机方法的类实例的引用。 %THIS 仅在非静态本机方法中有效。 此内置函数为非静态本机方法提供对类实例的访问权。
非静态本机方法在其类的特定实例上工作。 此对象实际上由 Java™作为参数传递到本机方法,但它不会显示在本机方法的原型或过程接口中。 在 Java 方法中,对象实例由 Java 保留字 this引用。 在 RPG 本机方法中,对象实例由 %THIS 内置函数引用。
* Method "vacationDays" is a method in the class 'Employee'
D vacationDays PR 10I 0 EXTPROC(*JAVA
D : 'Employee'
D : 'vacationDays')
* Method "getId" is another method in the class 'Employee'
D getId PR 10I 0 EXTPROC(*JAVA
D : 'Employee'
D : 'getId')
...
* "vacationDays" is an RPG native method. Since the STATIC keyword
* is not used, it is an instance method.
P vacationDays B EXPORT
D vacationDays PI 10I 0
D id_num S 10I 0
* Another Employee method must be called to get the Employee's
* id-number. This method requires an Object of class Employee.
* We use %THIS as the Object parameter, to get the id-number for
* the object that our native method "vacationDays" is working on.
C eval id_num = getId(%THIS)
C id_num chain EMPFILE
C if %found
C return VACDAYS
C else
C return -1
C endif
P vacationDays E