![]() |
generic-argument には、従来、T や U などの単一の大文字があります。
この例では、メイン メソッドは、2 つのパラメーターよりも大きい数字と小さい数字を見つけて表示します。T は Min メソッド (この場合は静的ジェネリック メソッド) に対するジェネリック引数です。Min メソッド は、2 つのパラメーター (どちらもジェネリック パラメーターと同じタイプのパラメーター) を予測します。T は IComparable インターフェイスを実装することがわかっているため、CompareTo メソッドを呼び出すことができます。
class-id GenericMath. method-id main static. 01 n1 binary-double. 01 n2 binary-double. set n1 to 999 set n2 to 100 display n1 space n2 display Min[binary-double](n1 n2) display Max[binary-double](n1 n2) goback. end method.
method-id Min using T static. constraints. constrain T implements type System.IComparable. procedure division using by value item1 as T item2 as T returning res as T. if item1::CompareTo(item2) < 0 set res to item1 else set res to item2 end-if end method.
method-id Max using T static. constraints. constrain T implements type System.IComparable. procedure division using by value item1 as T item2 as T returning res as T. if item1::CompareTo(item2) < 0 set res to item2 else set res to item1 end-if end method. end class.
ジェネリックのサンプルも参照してください。このサンプルは、Start > All Programs > Micro Focus Enterprise Developer > Samples > Visual COBOL Samples, under COBOL for .NET. に用意されています。