(j3.2006) Dynamic type of parent of dynamic type of an object

Van Snyder Van.Snyder
Wed Mar 2 15:12:33 EST 2016

I was asked "How does one get the dynamic type of the parent type of the
dynamic type of a polymorphic object?"

T is the base type.

A1 extends T and A2 extends A1
B1 extends T and B2 extends B1

X is polymorphic of declared type T and dynamic type either A2 or B2.

It is desired to run a method bound to A1 or B1, that has been
overridden in A2 and B2.  The overriding method is somewhat more
expensive than the overridden one, the overridden one produces the
desired result, the overriding one produces the desired result and also
some uninteresting stuff.

It can be done with a SELECT TYPE construct, but then one has the type
hierarchy wired into the source text of the code.  It would be nice to
do it automagically.

select type ( x )
class is ( A2 )
  y = x%a1%f(42)
class is ( B2 )
  y = x%a1%f(42)
class default
  stop "I don't know what to do here"
end select

More information about the J3 mailing list