インデクサ

インデクサは、そのアクセス機構がパラメータを取る点を除き、プロパティと似ています。インデクサを使用すると、配列と同様にクラスまたは値タイプのインスタンスに索引を付けることができます。

indexer-specification

indexer-header procedure-division-header access-modifier statement-block access-modifier statement-block

indexer-header

type-specifier access-modifier attribute-clause

次の例では、クラスが定義されます。このクラスには、値の割り当てと取得を行う手段として簡単なゲッタとセッタがあります。配列へのアクセスに使用される角括弧では、0 ベースの索引付けを使用します。丸括弧では 1 ベースの索引付けを使用します。

       class-id SimpleIndexer.
       01 myArray string occurs 100.

       indexer-id string.
       procedure division using by value i as binary-long.
       getter.
           set property-value to myArray[i]
       setter.
           set myArray[i] to property-value
       end indexer.

       end class.

プロパティのサンプルの IndexerDemo.cbl も参照してください。このサンプルは、[ スタート > すべてのプログラム > Micro Focus Enterprise Developer > Samples] のCOBOL for JVM の下にあります。