Syntax:
METHOD arca METHOD fred(i) METHOD kitt(foo, bar) METHOD kitt(foo, bar=3) METHOD jack(i=int, j=long 3) RETURNS int METHOD jill(i=int[,,], j=int) RETURNS int[] METHOD soup(i) SIGNALS Exception, DivideByZero
Introduces a method. See "Program Structure" for a description of methods.
The arguments part of a METHOD instruction, in parentheses immediately following the method name, is optional and defines a list of the arguments for the method. In this list, each argument must be given a name (which must not be the same as the name of any property in the class). Each argument is also optionally assigned a type and default value, using the usual rules of assignment. If there is no assignment, the type of the argument is assumed to be 'Rexx' (netrexx.lang.Rexx).
If there is no '=', or the expression to the right of the '=' returns just a type, the argument is required (that is, it must always be specified by the caller when the method is invoked). If an explicit value is given by the expression (as in the second "kitt" example above) then the argument is optional; if the caller does not provide it, then the value of the expression will be provided to the method instead.
In the Java implementation of NetRexx, optional arguments may be omitted 'from the right' only. That is, arguments may not be omitted to the left of arguments that are not omitted.
RETURNS describes the type of the result, which must be specified if the RETURN instructions in a method are to provide a result other than of type Rexx.
SIGNALS lists the types of exceptions that the method may signal.
Several other keyword options are allowed:
Math.sin(1.3) -- calls method sin(..) in class Math
(the name of the class may be omitted if it is listed in the USES phrase of the CLASS instruction).
Static methods are useful for providing function that is not associated with an object. They cannot be overridden in a subclass.
Constructor methods (where the method name exactly matches the class name) are allowed; their return type is assumed to be that of the class, and they simply create and modify 'this'. The first non-null clause in a constructor method may be a method call instruction where the method name is either 'this' or 'super', except if the class name is 'Object'. Note that 'this' and 'super' are valid method names only in this one context. See "Methods and constructors" for more details.
[ previous section | contents | next section ]
From 'netrexx.doc', version 1.00.
Copyright(c) IBM Corporation, 1996, 1997. All rights reserved. ©