[fpc-pascal] Java equivalent of Pascal's class reference functionality

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Thu Jun 9 01:17:46 CEST 2016


Hi,

I know this is not a Java forum, but thought maybe somebody here with
Object Pascal and Java knowledge could help (seeing that Java-only
developers might not know what I'm talking about).

Does Java have an equivalent feature of a Object Pascal language's Class
Reference.

For Example:
I want to write Java code that does similar to my Object Pascal code
shown below:

TVisClassRef = class of TVisitor ;

procedure ExecuteVisitor(const pData: TVisited; const pVisClass:
TVisClassRef);
var
  lVisitor: TVisitor;
begin
  lVisitor := pVisClass.Create;  // <<-- Important Part
  try
    pData.Iterate(lVisitor);
  finally
    lVisitor.Free;
  end;
end;

This procedure takes care of the tedious business of creating the
visitor, calling iterate, then freeing the visitor when done. I can pass
in various class references as the second argument (all descendants of
TVisitor), and different class instances will be created and used as needed.

I would love to know how I could do this in Java.

Regards,
  Graeme




More information about the fpc-pascal mailing list