9.2.11.Calling Instance Methods
Let T
be a user defined type
that has an instance method IM
. Let IT
be a scalar expression
having a compile time type of T
.
IT.IM ( [ parameter, .... ] )
This will call the instance method IM
of T
and will return whatever the IM
returns.
Similarly to member observers/mutators the compile time type of
IT
can be specified
explicitly:
(IT as T).IM ( [ parameter, .... ] )
This syntax however has an additional property in that it will
call the method of the type regardless of whether it is overloaded
in a subtype or not. Let ST
be
a subtype of T
and ST
that has the method IM
overloaded. Let IST
be a scalar expression that represents
an instance of ST
.
Then:
(IST as T).IM ( [ parameter, ... ] )
will call the method IM
as
defined in T
, whereas
IST.IM ( [ parameter, ... ] )
will call the method IM
as
defined in ST
.
Example9.10.Calling Overloaded Instance Methods
CREATE TYPE UDT_BASE method A () returns integer; CREATE TYPE UDT_SUB under UDT_BASE OVERRIDING method A () returns integer; create method A () returns integer for UDT_BASE { return 1; } create method A () returns integer for UDT_SUB { return 2; } select new UDT_SUB ().A() as IMPLICIT, (new UDT_SUB() as UDT_BASE).A() as EXPLICIT;
This will return:
IMPLICIT EXPLICIT ---------------------------- 2 1
This is done so the overloaded methods can call the base type methods.