The title is pretty much it…
Why would you ever want to use the constructor constraint?
It’s clearly implied by the class constraint.
If you use it alone, you can’t do anything with the thing you’ve created.
Why does it even exist?
Additional info:
Just as a note, the following code doesn’t compile until you add the “constructor” constraint:
program Project3;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
type
TSomeClass<T: class> = class
function GetType: T;
end;
{ TSomeClass<T> }
function TSomeClass<T>.GetType: T;
begin
Result := T.Create;
end;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
No it’s not. The constructor constraint requires that the type has a public, parameterless constructor – and then allows that constructor to be called.
Not all classes have a public parameterless constructor.